JDBC与数据库连接汇总
1、Oracle数据库(thin模式)
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); //加载驱动 下同 String url="jdbc:oracle:thin:@localhost:1521:myDB"; //myDB为数据库名 下同 String user="test"; String password="test"; Connection conn= DriverManager.getConnection(url,user,password);
2、DB2数据库
Class.forName("com.ibm.db2.jdbc.app.DB2Driver").newInstance(); String url="jdbc:db2://localhost:50000/myDB"; String user="admin"; String password=""; Connection conn= DriverManager.getConnection(url,user,password);
3、Sql Server7.0/2000数据库
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=myDB"; String user="sa"; String password=""; Connection conn= DriverManager.getConnection(url,user,password);
Sql Server2005数据库
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance(); String url="jdbc:sqlserver://localhost:1433;DatabaseName=myDB"; String user="sa"; String password=""; Connection conn= DriverManager.getConnection(url,user,password);
4、Sybase数据库
Class.forName("com.sybase.jdbc.SybDriver").newInstance(); String url ="jdbc:sybase:Tds:localhost:5007/myDB"; Properties sysProps = System.getProperties(); String user="userid"; String password="user_password"; Connection conn= DriverManager.getConnection(url,user,password);
5、Informix数据库
Class.forName("com.informix.jdbc.IfxDriver").newInstance(); String url = "jdbc:informix-sqli://localhost:1526/bisprod:INFORMIXSERVER=myDB" String user="informix"; String password="informix"; Connection conn= DriverManager.getConnection(url,user,password);
6、MySQL数据库
Class.forName("com.mysql.jdbc.Driver").newInstance(); String url ="jdbc:mysql://localhost:3306/myDB?user=root&password=password"; Connection conn= DriverManager.getConnection(url);http://xzh.i3geek.com