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

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



thank you very much ,i'll try it .

"Kamil Sykora [MSFT]" <kamils@xxxxxxxxxxxxxxxxxxxx> дÈëÏûÏ¢ÐÂÎÅ:nrIaRzw5FHA.3788@xxxxxxxxxxxxxxxxxxxxxxxx
> 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: ... 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: How do I register this data source with JNDI?
    ... However I am running tests outside of the container and was wondering what I can do to create and register the above datasource so that it can be looked up through a JNDI call. ... You need to add a JNDI provider to your classpath, do whatever magic it takes to make it usable, set the java.naming.factory.initial system property to refer to the initial context factory class for that provider, then in your test framework, create a context and bind the datasource to it. ... Or, if you want to use the same XML you use inside the container, you could write a little XML parser to read those configuration files. ...
    (comp.lang.java.programmer)