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

MYSQL
使用mysql的mysqldump实现自动备份
MySQL数据导出和导入工具:mysqldump
怎样从Windows命令行启动您的MySQL
细化解析实现MySQL查询结果的分页显示
强大的工具 MySQL客户端命令行应用技巧
MySQL 5.0.16中出现乱码问题的解决方法
phpMyBackupPro备份恢复Mysql数据库
如何才能关闭MySQL数据库中错误提示音
数据库竟然崩溃了!马上让它恢复正常!
怎么显示 MySQL 数据库里表的概要呢?
自动恢复MySQL数据库的日志文件全教程
实例解说MySQL数据库中文问题的解决方案
优化MySQL数据库性能的几招儿好办法
MySQL加密函数保护Web网站敏感数据
使用PHP小程序清除Mysql中恼人的死连接
Mysql中用utf8存储而用gbk输出的实现
浅谈怎么才能在MySQL中直接储存图片
用特殊的MySQL运算符获得更多数据比较功能
MySQL数据库中的重要资料需要怎样保护?
假如忘记MySQL root密码应当怎样找回

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 101 ::
收藏到网摘: 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);