Re: how could i do for use datasource without JNDI.
- From: "˥˥" <me@xxxxxxxx>
- Date: Sat, 12 Nov 2005 13:50:43 +0800
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
> |
> |
>
.
- References:
- how could i do for use datasource without JNDI.
- From: ˥˥
- RE: how could i do for use datasource without JNDI.
- From: Kamil Sykora [MSFT]
- how could i do for use datasource without JNDI.
- Prev by Date: RE: how could i do for use datasource without JNDI.
- Next by Date: RE: jdbc & java 1.5?
- Previous by thread: RE: how could i do for use datasource without JNDI.
- Next by thread: Commons DBCP pooling problem
- Index(es):
Relevant Pages
|
Loading