找回密码
 立即注册
企业管理 2022-09-22 92 0star收藏 版权: . 保留作者信息 . 禁止商业使用 . 禁止修改作品
此文中的代码首要列出连接数据库的重要代码,其他访问数据库代码掉
1、Oracle8/8i/9i数据库(thin模式)
Class.forName(oracle.jdbc.driver.OracleDriver).newInstance();
Stringurl=jdbc<imgsrc="static/image/smiley/default/shocked.gif"smilieid="6"border="0"alt=""/>racle:thin<imgsrc="static/image/smiley/default/huffy.gif"smilieid="5"border="0"alt=""/>localHOST:1521<imgsrc="static/image/smiley/default/shocked.gif"smilieid="6"border="0"alt=""/>rcl;
//orcl为数据库的SID
Stringuser=test;
Stringpassword=test;
Connectionconn=DriverManager.getConnection(url,user,password);
2、DB2数据库
Class.forName(com.ibm.db2.jdbc.app.DB2Driver).newInstance();
Stringurl=jdbc:db2://localHOST:5000/sample;
//sample为你的数据库名
Stringuser=admin;
Stringpassword=;
Connectionconn=DriverManager.getConnection(url,user,password);
3、SqlServer7.0/2000数据库
Class.forName(com.microsoft.jdbc.sqlserver.SQLServerDriver).newInstance();
Stringurl=jdbc:microsoft:sqlserver://localHOST:1433;DatabaseName=mydb;
//mydb为数据库
Stringuser=sa;
Stringpassword=;
Connectionconn=DriverManager.getConnection(url,user,password);
4、Sybase数据库
Class.forName(com.sybase.jdbc.SybDriver).newInstance();
Stringurl=jdbc:sybase:Tds:localHOST:5007/myDB;
//myDB为你的数据库名
PropertiessysProps=System.getProperties();
SysProps.put(user,userid);
SysProps.put(password,user_password);
Connectionconn=DriverManager.getConnection(url,SysProps);
5、Informix数据库
Class.forName(com.informix.jdbc.IfxDriver).newInstance();
Stringurl=
jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
user=testuser;password=testpassword;
//myDB为数据库名
Connectionconn=DriverManager.getConnection(url);
6、MySQL数据库
Class.forName(org.gjt.mm.mysql.Driver).newInstance();
Stringurl=jdbc:mysql://localHOST/myDB?user=softpassword=soft1234useUnicode=truecharacterEncoding=8859_1
//myDB为数据库名
Connectionconn=DriverManager.getConnection(url);
7、PostgreSQL数据库
Class.forName(org.postgresql.Driver).newInstance();
Stringurl=jdbc:postgresql://localHOST/myDB
//myDB为数据库名
Stringuser=myuser;
Stringpassword=mypassword;
Connectionconn=DriverManager.getConnection(url,user,password);
Java连接各种数据库的实例.txt

(The code in this article firstly lists the important codes for connecting to the database, and other codes for accessing the database are omitted.
1. Oracle8/8i/9i database (thin mode)
Class.forName(oracle.jdbc.driver.OracleDriver).newInstance();
Stringurl=jdbc<imgsrc="static/image/smiley/default/shocked.gif"smilieid="6"border="0"alt=""/>racle:thin<imgsrc="static/image/smiley/default/ huffy.gif"smilieid="5"border="0"alt=""/>localHOST:1521<imgsrc="static/image/smiley/default/shocked.gif"smilieid="6"border="0"alt =""/>rcl;
//orcl is the SID of the database
Stringuser=test;
Stringpassword=test;
Connectionconn=DriverManager.getConnection(url,user,password);
2. DB2 database
Class.forName(com.ibm.db2.jdbc.app.DB2Driver).newInstance();
Stringurl=jdbc:db2://localHOST:5000/sample;
//sample is your database name
Stringuser=admin;
Stringpassword=;
Connectionconn=DriverManager.getConnection(url,user,password);
3, SqlServer7.0/2000 database
Class.forName(com.microsoft.jdbc.sqlserver.SQLServerDriver).newInstance();
Stringurl=jdbc:microsoft:sqlserver://localHOST:1433;DatabaseName=mydb;
//mydb is the database
Stringuser=sa;
Stringpassword=;
Connectionconn=DriverManager.getConnection(url,user,password);
4. Sybase database
Class.forName(com.sybase.jdbc.SybDriver).newInstance();
Stringurl=jdbc:sybase:Tds:localHOST:5007/myDB;
//myDB is your database name
PropertiessysProps=System.getProperties();
SysProps.put(user,userid);
SysProps.put(password,user_password);
Connectionconn=DriverManager.getConnection(url,SysProps);
5. Informix database
Class.forName(com.informix.jdbc.IfxDriver).newInstance();
Stringurl=
jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
user=testuser;password=testpassword;
//myDB is the database name
Connectionconn=DriverManager.getConnection(url);
6. MySQL database
Class.forName(org.gjt.mm.mysql.Driver).newInstance();
Stringurl=jdbc:mysql://localHOST/myDB?user=softpassword=soft1234useUnicode=truecharacterEncoding=8859_1
//myDB is the database name
Connectionconn=DriverManager.getConnection(url);
7. PostgreSQL database
Class.forName(org.postgresql.Driver).newInstance();
Stringurl=jdbc:postgresql://localHOST/myDB
//myDB is the database name
Stringuser=myuser;
Stringpassword=mypassword;
Connectionconn=DriverManager.getConnection(url,user,password);
Instances of Java connecting to various databases.txt)

[下载]22295659346.rar




上一篇:Eclipse – 整合开发工具【中文教程】
下一篇:java连接Access数据库代码