当前位置: 首页 > 图文教程 > 数据库 > MYSQL > Java连接各种数据库的实例

MYSQL
SQL语句因编写不当 可能导致系统不安全
教你如何缩小SQL Server数据库日志文件
sql2000卸载了后重新安装时不能安装的解决办法
MySQL密码忘记了,别害怕
如何防止插入删除表造成的数据库死锁
MySQL是否值得我们选择的正反五个理由
8种方法优化MySQL性能
MySQL服务器默认安装之后如何调节性能
MySQL数据库引擎快速指导
分析MS SQL Server里函数的两种用法
MYSQL数据库初学者使用指南
MySQL数据库安全配置指南
教你如何在MySQL数据库中直接储存图片
如何应用SQL Server DBCC避免堵塞
运用Mysql语句生成后门木马的具体方法
MySQL安全性指南 (1)
你的MySQL安全了吗?加铸23道安全门
MySQL中文参考手册---安装MySQL
MySQL管理员指南之--MySQL用户管理
如何利用MySQL加密函数保护Web网站敏感数据

MYSQL 中的 Java连接各种数据库的实例


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 40 ::
收藏到网摘: n/a

1、Oracle8/8i/9i数据库(thin模式)

2、DB2数据库

以下为引用的内容:
Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
String url="jdbc:db2://localhost:5000/sample";
//sample为你的数据库名
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";
//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";
//myDB为你的数据库名
Properties sysProps = System.getProperties();
SysProps.put("user","userid");
SysProps.put("password","user_password");
Connection conn= DriverManager.getConnection(url, SysProps);

5、Informix数据库

以下为引用的内容:
Class.forName("com.informix.jdbc.IfxDriver").newInstance();
String url =
"jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
user=testuser;password=testpassword";
//myDB为数据库名
Connection conn= DriverManager.getConnection(url);

6、MySQL数据库

以下为引用的内容:
Class.forName("org.gjt.mm.MySQL.Driver").newInstance();
String url ="jdbc:MySQL://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
//myDB为数据库名
Connection conn= DriverManager.getConnection(url);

7、PostgreSQL数据库

以下为引用的内容:

Class.forName("org.postgresql.Driver").newInstance();
String url ="jdbc:postgresql://localhost/myDB"
//myDB为数据库名
String user="myuser";
String password="mypassword";
Connection conn= DriverManager.getConnection(url,user,password);