常用数据库的链接方法
连接 mysql 数据库,代码如下:
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://127.0.0.1/myDatabase";
String user = "user";
String password = "password";
Connection conn = DriverManager.getConnection(url, user, password);
连接 oracle 数据库,代码如下:
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@127.0.0.1:1521:myOracleSID";
String user = "user";
String password = "password";
Connection conn = DriverManager.getConnection(url, user, password);
连接 MS SQL Server 数据库,代码如下:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=myDbName";
String user = "user";
String password = "password";
Connection conn = DriverManager.getConnection(url, user, password);
连接 mysql 数据库,代码如下:
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://127.0.0.1/myDatabase";
String user = "user";
String password = "password";
Connection conn = DriverManager.getConnection(url, user, password);
连接 oracle 数据库,代码如下:
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@127.0.0.1:1521:myOracleSID";
String user = "user";
String password = "password";
Connection conn = DriverManager.getConnection(url, user, password);
连接 MS SQL Server 数据库,代码如下:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=myDbName";
String user = "user";
String password = "password";
Connection conn = DriverManager.getConnection(url, user, password);