**1.Oracle数据库(thin模式)**
Class.forName("oracle.jdbc.driver.OracleDriver");//数据库驱动字符串
String url="jdbc:oracle:thin:@localhost:1521:orcl";//连接URL字符串 orcl为数据库的SID
String user="scott";//数据库用户名
String password="tiger";//数据库密码
Connection conn=DriverManager.getConnection(url,user,password);
**2.DB2数据库**
Class.forName("com.ibm.db2.jdbc.app.DB2Driver");//数据库驱动字符串
String url="jdbc:db2://localhost:5000/sample";//连接URL字符串 sample为数据库的名字
String user="admin";//数据库用户名
String password="admin";//数据库密码
Connection conn=DriverManager.getConnection(url,user,password);
**3.MySQL数据库**
Class.forName("com.mysql.Driver");//数据库驱动字符串
String url="jdbc:mysql://localhost:3306/myDB";//连接URL字符串 myDB为数据库的名字
String user="root";//数据库用户名
String password="root";//数据库密码
Connection conn=DriverManager.getConnection(url,user,password);
**4.SQL Server数据库**
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//数据库驱动字符串
String url="jdbc:sqlserver://localhost:1433;DatabaseName=epet";//连接URL字符串 epet为数据库的名字
String user="sa";//数据库用户名
String password="sa";//数据库密码
Connection conn=DriverManager.getConnection(url,user,password);
**5.H2数据库**
Class.forName("org.h2.Driver");//数据库驱动字符串
String url="jdbc:h2:~/test";//连接URL字符串 test为数据库的名字
String user="sa";//数据库用户名
String password="sa";//数据库密码
Connection conn=DriverManager.getConnection(url,user,password);
**6.PostgreSQL数据库**
Class.forName("org.postgresql.Driver");//数据库驱动字符串
String url="jdbc:postgresql://localhost:5432/testdb";//连接URL字符串 testdb为数据库的名字
String user="postgresql";//数据库用户名
String password="postgresql";//数据库密码
Connection conn=DriverManager.getConnection(url,user,password);
JDBC连接各大数据库
最新推荐文章于 2023-05-24 22:06:18 发布