1.jdbc联接数据库;
(1)可以使用资源文件配置数据库信息
(2)可以使用初始化参数配置数据库信息
2.DataSource+JNDI
需要配置data;source信息
这个我不太明白,望指教
3.Hibernate等ORM技术
4.Tomcat中直接配置
疑问:2.JNDI的配置只需在web.xml配置就醒行了吗
4.用的多吗,在程序中怎样调用
------解决方案--------------------
http://topic.csdn.net/t/20021005/16/1073737.html
http://topic.csdn.net/t/20030105/14/1328229.html
JDNI 没用过,到现在为止用过的是ibatis,最基本的jdbc,DataSource
上面是JDNI的两个贴,自己看看吧,希望有帮助
------解决方案--------------------
1. MySQL(http://www.mysql.com)
Class.forName( "org.gjt.mm.mysql.Driver " );
cn = DriverManager.getConnection( "jdbc:mysql://MyDbComputerNameOrIP:3306/myDatabaseName ", sUsr, sPwd );
2. PostgreSQL(http://www.de.postgresql.org)pgjdbc2.jar
Class.forName( "org.postgresql.Driver " );
cn = DriverManager.getConnection( "jdbc:postgresql://MyDbComputerNameOrIP/myDatabaseName ", sUsr, sPwd );
3. Oracle(http://www.oracle.com/ip/deploy/database/oracle9i/)classes12.zip
Class.forName( "oracle.jdbc.driver.OracleDriver " );
cn = DriverManager.getConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL ", sUsr, sPwd );
4. Sybase(http://jtds.sourceforge.net)jconn2.jar
Class.forName( "com.sybase.jdbc2.jdbc.SybDriver " );
cn = DriverManager.getConnection( "jdbc:sybase:Tds:MyDbComputerNameOrIP:2638 ", sUsr, sPwd );
//(Default-Username/Password: "dba "/ "sql ")
5. Microsoft SQLServer(http://jtds.sourceforge.net)
Class.forName( "net.sourceforge.jtds.jdbc.Driver " );
cn = DriverManager.getConnection( "jdbc:jtds:sqlserver://MyDbComputerNameOrIP:1433/master ", sUsr, sPwd );
6. Microsoft SQLServer(http://www.microsoft.com)
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver " );
cn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://MyDbComputerNameOrIP:1433;databaseName=master ", sUsr, sPwd );
7. ODBC
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver " );
Connection cn = DriverManager.getConnection( "jdbc:odbc: " + sDsn, sUsr, sPwd );
8.DB2(新添加)
Class.forName( "com.ibm.db2.jdbc.net.DB2Driver ");
String url= "jdbc:db2://192.9.200.108:6789/SAMPLE "
cn = DriverManager.getConnection( url, sUsr, sPwd );
9.Microsoft SQL Server series (6.5, 7.x and 2000) and Sybase 10
JDBC Name: jTDS
URL: http://jtds.sourceforge.net/
Version: 0.5.1
Download URL: http://sourceforge.net/project/showfiles.php?group_id=33291
语法:
Class.forName( "net.sourceforge.jtds.jdbc.Driver ");
Connection con = DriverManager.getConnection( "jdbc:jtds:sqlserver://host:port/database ", "user ", "password ");
or
Connection con = DriverManager.getConnection( "jdbc:jtds:sybase://host:port/database ", "user ", "password ");
10.Postgresql
JDBC Name: PostgreSQL JDBC
URL: http://jdbc.postgresql.org/
Version: 7.3.3 build 110
Download URL: http://jdbc.postgresql.org/download.html
语法:
Class.forName( "org.postgresql.Driver ");
Connection con=DriverManager.getConnection( "jdbc:postgresql://host:port/database ", "user ", "password ");
11.IBM AS400主机在用的JDBC语法
有装V4R4以上版本的Client Access Express
可以在C:\Program Files\IBM\Client Access\jt400\lib
找到 driver 档案 jt400.zip,并更改扩展名成为 jt400.jar
语法:
java.sql.DriverManager.registerDriver (new com.ibm.as400.access.AS400JDBCDriver ());
Class.forName( "com.ibm.as400.access.AS400JDBCConnection ");