日期:2014-05-16  浏览次数:20474 次

JDBC连接各种数据库配置

jdbc连接数据库的代码如下:
String driver_class = "oracle.jdbc.driver.OracleDriver";
		Class.forName(driver_class);
		
String url = "jdbc:oracle:thin:@localhost:1521:beipiao";
String username = "admin";
String password = "1234";
Connection conn = DriverManager.getConnection(url,username,password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select 1 from dual ");
while(rs.next()){
    System.out.println(rs.getInt(1));
}
conn.close();


1、Oracle8/8i/9i数据库(thin模式)
driver_class = oracle.jdbc.driver.OracleDriver
url = jdbc:oracle:thin:@localhost:1521:orcl


2、DB2数据库
driver_class = com.ibm.db2.jdbc.app.DB2Driver
url = jdbc:db2://localhost:5000/sample


3、Sql Server7.0/2000数据库
driver_class = com.microsoft.jdbc.sqlserver.SQLServerDriver
url = jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb


4、Sybase数据库
driver_class = com.sybase.jdbc.SybDriver
url = jdbc:sybase:Tds:localhost:5007/myDB


5、Informix数据库
driver_class = com.informix.jdbc.IfxDriver
url = jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
user=testuser;password=testpassword


6、MySQL数据库
driver_class = com.mysql.jdbc.Driver
url = jdbc:mysql://127.0.0.1:3306/databasename?useUnicode=true&characterEncoding=gbk

7、Access数据库
driver_class = sun.jdbc.odbc.JdbcOdbcDriver
url = jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=databasename.mdb