当前位置: 技术问答>java相关
那位兄弟给段代码:连接Oracle数据库的。
来源: 互联网 发布时间:2015-08-05
本文导语: 哈哈哈,不好意思,没连过。 | ============ORACLE 8i============================ Class.forName ("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@myhost:1521:orcl", ...
哈哈哈,不好意思,没连过。
|
============ORACLE 8i============================
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@myhost:1521:orcl",
"scott", "tiger");
=============MySQL=================================
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://myhost:3306/dbname","user","passwd");
============InfoMax================================
Class.forName("com.informix.jdbc.IfxDriver");
conn = DriverManager.getConnection("jdbc:informix-sqli://myhost:1533:informixserver=myserver;user=rdtest;password=test");
============InforMix================================
Class.forName("com.informix.jdbc.IfxDriver");
conn = DriverManager.getConnection("jdbc:informix-sqli://myhost:1533:informixserver=myserver;user=rdtest;password=test");
=============SQLServer2000=========================
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection
("jdbc:microsoft:sqlserver://server1:1433","username","password");
///////////////////////////////////
jdbc driver download:
SQLServer:http://www.microsoft.com/sql/downloads/default.asp
MySQL:http://www.mysql.com/downloads/api-jdbc.html
Oracle:http://otn.oracle.com/software/content.html
---------------------DB2--------------------
--------------------- --------------------
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();//For Application
String url = "jdbc:db2:sample";
con = DriverManager.getConnection(url, userid, passwd);
Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").newInstance();//For Applet
String url = "jdbc:db2:// "+server+":"+port+"/sample";
con = DriverManager.getConnection(url, userid, password );
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@myhost:1521:orcl",
"scott", "tiger");
=============MySQL=================================
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://myhost:3306/dbname","user","passwd");
============InfoMax================================
Class.forName("com.informix.jdbc.IfxDriver");
conn = DriverManager.getConnection("jdbc:informix-sqli://myhost:1533:informixserver=myserver;user=rdtest;password=test");
============InforMix================================
Class.forName("com.informix.jdbc.IfxDriver");
conn = DriverManager.getConnection("jdbc:informix-sqli://myhost:1533:informixserver=myserver;user=rdtest;password=test");
=============SQLServer2000=========================
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection
("jdbc:microsoft:sqlserver://server1:1433","username","password");
///////////////////////////////////
jdbc driver download:
SQLServer:http://www.microsoft.com/sql/downloads/default.asp
MySQL:http://www.mysql.com/downloads/api-jdbc.html
Oracle:http://otn.oracle.com/software/content.html
---------------------DB2--------------------
--------------------- --------------------
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();//For Application
String url = "jdbc:db2:sample";
con = DriverManager.getConnection(url, userid, passwd);
Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").newInstance();//For Applet
String url = "jdbc:db2:// "+server+":"+port+"/sample";
con = DriverManager.getConnection(url, userid, password );
|
呵呵,好象已经很全了
补充oracle的连接方法:
DriverManager.registerDriver (new OracleDriver());
Connection conn73 = DriverManager.getConnection
("jdbc:oracle:oci8:@ora8idev","scott","tiger");
补充oracle的连接方法:
DriverManager.registerDriver (new OracleDriver());
Connection conn73 = DriverManager.getConnection
("jdbc:oracle:oci8:@ora8idev","scott","tiger");