常见数据库连接
1、mysql
driver = "com.mysql.jdbc.Driver";
url = "jdbc:mysql://localhost:3306/数据库名";
con = DriverManager.getConnection(url,muser,password);
2、Oracle
driver = “oracle.jdbc.driver.OracleDriver”;
usl = "jdbc:oracle:thin:@localhost:1521:数据库服务名";
con = DriverManager.getConnection(url,muser,password);
( 注:Oracle下获得数据库服务名:
1、在SQL plus环境下,右键数据库选项 “属性”——“连接详细资料” 找到连接名 @XXX。XXX就是数据库服务名
2、在SQL plus下,运行 select global_name form global_name;
3、查看服务下的端口:
运行Net Manager ,在 “本地”——“服务名”——找到对应服务的端口)
3、Sqlserver
driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
url = "jdbc:sqlserver://localhost:1433;DatabaseName = 数据库名";
con = DriverManager.getConnection(url,muser,password);
(文件数据库)
4、access
url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+绝对路径+"\\db2.mdb";
con = DriverManager.getConnection(url);
5、Derby
driver = "org.apache.derby.jdbc.EmbeddedDriver"; //嵌入式数据库
url = "jdbc:derby:数据库名;create = true";
con = DriverManager.getConnection(url);