public Connection getConnection(){//事先导入驱动
try{
Class.forname("sun.jdbc.odbc.jdbcodbcDriver");//加载驱动
System.out.println("驱动加载完毕");
}catch(ClassNotFoundException e){
e.printStackTrace();
}
try{
Connecion con=DriverManager.getConnecion("jdbc:odbc:数据库名成","用户名","密码");//创建连接对象,即已经连接到数据库
system.out.println("连接成功!");
}
catch(exception e){
e.printStackTrace();
}
}
public static Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
return conn;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
String driverName = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:ORACLE9I";
Class.forName(driverName);
Connection con = null;
con = DriverManager.getConnection(url,"shown","dbwork");
oracle数据库
oracle.jdbc.driver.OracleDriver
jdbc:oracle:thin:@127.0.0.1:1521:orcl