RE: how could i do for use datasource without JNDI.



Hello,

You can use code similar to this to use a datasource without JNDI:

import java.sql.*;

public class datasource {
public static void main(String[] args) throws Exception {
//SQL Server 2000 Driver
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//SQL Server 2005 Driver
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

com.microsoft.jdbcx.sqlserver.SQLServerDataSource ds1 = new
com.microsoft.jdbcx.sqlserver.SQLServerDataSource();
ds1.setServerName("localhost");
ds1.setDatabaseName("pubs");
ds1.setUser("uid");
ds1.setPassword("pwd");

com.microsoft.sqlserver.jdbc.SQLServerDataSource ds2 = new
com.microsoft.sqlserver.jdbc.SQLServerDataSource();
ds2.setServerName("localhost");
ds2.setDatabaseName("pubs");
ds2.setUser("uid");
ds2.setPassword("pwd");


Connection cn = ds1.getConnection();

DatabaseMetaData dbmd = cn.getMetaData();
System.out.println( "Driver name: " + dbmd.getDriverName());
System.out.println( "Driver version: " + dbmd.getDriverVersion());
System.out.println( "Server product: " + dbmd.getDatabaseProductName());
System.out.println( "Server version: " +
dbmd.getDatabaseProductVersion());

cn.close();
cn = ds2.getConnection();

dbmd = cn.getMetaData();
System.out.println( "Driver name: " + dbmd.getDriverName());
System.out.println( "Driver version: " + dbmd.getDriverVersion());
System.out.println( "Server product: " + dbmd.getDatabaseProductName());
System.out.println( "Server version: " +
dbmd.getDatabaseProductVersion());


cn.close();


}
}



Thanks,
Kamil

Kamil Sykora [MSFT]
Microsoft Developer Support - Webdata

This posting is provided "AS IS", with no warranties, and confers no
rights.

Please do not send email directly to this alias. This alias is for
newsgroup
purposes only.
--------------------
| From: "˥˥" <me@xxxxxxxx>
| Subject: how could i do for use datasource without JNDI.
| Date: Fri, 4 Nov 2005 23:29:37 +0800
|
| hi:
| now i'm building a java application.but there is no JNDI env in my
| project.
| and i want use datasource.i read the manual from the MS's website.but i
| couldn't find info for this.
| how could i do?
| Thx!
| gg from
| China
|
2005-11-04
|
|

.



Relevant Pages

  • Re: how could i do for use datasource without JNDI.
    ... > You can use code similar to this to use a datasource without JNDI: ... > public class datasource { ... > Please do not send email directly to this alias. ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: jndi
    ... DataSource, as defined by the config file. ... The JNDI service maintains it ... instance, then when Tomcat starts, it reads the configuration file and says, ... scheme...all of that is handled by the JNDI service. ...
    (comp.lang.java)
  • Re: how to test jndi connection pooling
    ... just stub out a DataSource class by implementing the ... MyClassToTest myClass = new MyClassToTest; ... this new class should not be doing any JNDI lookups. ... Object [but aren't all java objects POJO?]); ...
    (comp.lang.java.programmer)
  • Re: Binding to JNDI datasource - please help
    ... I'm relatively new to JNDI concepts and need some help. ... > connection datasource as a url variable. ... > How do I use this JNDI name to create a connection? ... > literature I have read says to bind the resource manager connection ...
    (comp.lang.java.programmer)

Loading