连接mysql
import java.sql.*;
public class aa{
public static void main(String[] args) {
Connection con = null;
try {
Class.forName("oracle.jdbc.OracleDriver");
System.out.println("sssssssss");
try {
con = DriverManager.getConnection(
"jdbc:oracle:thin:@127.0.0.1:1521:orcl",
"scott", "oracle");
System.out.println("aaaaaaaaaaaaaa");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("wwww");
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("rrrrrrrrrrr");
}
}
}
连接sqlserver
package MOdel;
import java.sql.*;
public class connDb {
Connection con = null;
public Connection getcon(){
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("sssssssss");
try {
con = DriverManager.getConnection(
"jdbc:sqlserver://127.0.0.1:1433;DatabaseName=xiaoyouwang",
"sa", "123");
System.out.println("aaaaaaaaaaaaaa");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
}
连接oracle
package MOdel;
import java.sql.*;
public class connDbOracle{
public static void main(String[] args) {
Connection con = null;
try {
Class.forName("oracle.jdbc.OracleDriver");
System.out.println("sssssssss");
try {
con = DriverManager.getConnection(
"jdbc:oracle:thin:@127.0.0.1:1521:orcl",
"scott", "oracle");
System.out.println("aaaaaaaaaaaaaa");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("wwww");
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("rrrrrrrrrrr");
}
}
}