博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用JDBC连接各种数据库(总结)
阅读量:4158 次
发布时间:2019-05-26

本文共 2859 字,大约阅读时间需要 9 分钟。

1、 连接Oracle 8/8i/9i数据库

Class.forName("oracle.jdbc.driver.OracleDriver");
String url=”jdbc: oracle:thin:@192.168.0.1:1521:orcl”;
String user=”test”;
String password=”test”;
Connection con = DriverManager.getConnection(url,user,password);
oracle.jdbc.driver.OracleDriver:驱动程序类的名称
jdbc: oracle:thin: 使用thin 模式连接
192.168.0.1: 数据库的ip 地址
1521: 数据库服务的端口号。这是Oracle的默认值。
Orcl: 数据库的SID
User: 访问数据库的用户名。
Password: 访问数据库的密码。
2、 连接DB2数据库
Class.forName("com.ibm.db2.jdbc.app.DB2Driver");
String url=”jdbc:db2://127.0.0.1:5000:sample”;
String user=”admin”;
String password=””;
Connection con = DriverManager.getConnection(url,user,password);
com.ibm.db2.jdbc.app.DB2Driver:驱动程序类的名称
127.0.0.1: 数据库的ip 地址
5000: 数据库服务的端口号。
Sample: 数据库的名称。
User: 访问数据库的用户名。
Password: 访问数据库的密码。
3、 连接SQL Server 7.0/2000数据库
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url=”jdbc: microsoft:sqlserver://localhost:1433;DatabaseName=mydb”;
String user=”sa”;
String password=””;
Connection con = DriverManager.getConnection(url,user,password);
com.microsoft.jdbc.sqlserver.SQLServerDriver:驱动程序类的名称
localhost: 数据库的地址
1433: 数据库服务的端口号。
Mydb: 数据库的名称
User: 访问数据库的用户名。
Password: 访问数据库的密码。
4、 连接Sybase数据库
Class.forName("com.sybase.jdbc.SybDriver");
String url=”jdbc:sybase:Tds:localhost:5007/myDB”;
Properties sysProps=System.getProperties();
SysPros.put(“user”,”userid”);
SysPros.put(“password”,”user_password”);
Connection con = DriverManager.getConnection(url);
com.sybase.jdbc.SybDriver:驱动程序类的名称
localhost: 数据库的地址
5007: 数据库服务的端口号。
Mydb: 数据库的名称
Userid: 访问数据库的用户名。
User_password: 访问数据库的密码。
5、 连接Informix数据库
Class.forName("com.informix.jdbc.IfxDriver");
String url=”jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=
myserver;user=testuser;password=testpassword”;
Connection con = DriverManager.getConnection(url);
com.informix.jdbc.IfxDriver:驱动程序类的名称
123.45.67.89: 数据库的地址
1533: 数据库服务的端口号。
Mydb: 数据库的名称
Myserver:数据库服务器的名称。
Tstuser: 访问数据库的用户名。
Tsetpassword: 访问数据库的密码。
6、 连接MySQL数据库
Class.forName("org.git.mm.mysql.Driver");
Stringurl=”jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8895_1”
Connection con = DriverManager.getConnection(url);
org.git.mm.mysql.Driver:驱动程序类的名称
localhost: 数据库的地址
Mydb: 数据库的名称
Soft:访问数据库的用户名。
Soft1234: 访问数据库的密码。
8895_1: 使用的字符集。
7、 连接PostgreSQL数据库
Class.forName("org.postgresql.Driver");
String url=”jdbc:postgresql://localhost/myDB”;
String user=”myuser”;
String password=”mypassword”;
Connection con = DriverManager.getConnection(url,user,password);
org.postgresql.Driver:驱动程序类的名称
localhost: 数据库的地址
Mydb: 数据库的名称
Myuser:访问数据库的用户名。
Mypassword: 访问数据库的密码。
8、 连接Access数据库
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url=”jbdc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=”+application.getRealPath(“/Date/ReportDemo.mdb”)
Connection con = DriverManager.getConnection("jdbc:odbc:sun", "", "");

 

转载地址:http://vryxi.baihongyu.com/

你可能感兴趣的文章
Android 的source (需安装 git repo)
查看>>
LOCAL_PRELINK_MODULE和prelink-linux-arm.map
查看>>
Simple Guide to use the gdb tool in Android environment
查看>>
Netconsole to capture the log
查看>>
Build GingerBread on 32 bit machine.
查看>>
How to make SD Card world wide writable
查看>>
Detecting Memory Leaks in Kernel
查看>>
Linux initial RAM disk (initrd) overview
查看>>
Timestamping Linux kernel printk output in dmesg for fun and profit
查看>>
There's Much More than Intel/AMD Inside
查看>>
CentOS7 安装MySQL 5.6.43
查看>>
使用Java 导入/导出 Excel ----Jakarta POI
查看>>
本地tomcat 服务器内存不足
查看>>
IntelliJ IDAE 2018.2 汉化
查看>>
Openwrt源码下载与编译
查看>>
我和ip_conntrack不得不说的一些事
查看>>
Linux 查看端口使用情况
查看>>
文件隐藏
查看>>
两个linux内核rootkit--之二:adore-ng
查看>>
两个linux内核rootkit--之一:enyelkm
查看>>