import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Admin {
public static void main(
String args[]) {
}
public static Connection getConnetion(
String mode) {
String driver = "oracle.jdbc.OracleDriver";
String url = "jdbc:oracle:thin@localhost:1521:table";
String user = "user";
String password = "password";
// oracle
if (mode.equals("oracle")) {
driver = "oracle.jdbc.OracleDriver";
url = "jdbc:oracle:thin@localhost:1111:table";
}
// sql
else if (mode.equals("sql")) {
driver = "sun.jdbc.odbc.JdbcOdbcDriver";
url = "jdbc:odbc:table";
}
// MySql
else if (mode.equals("MySql")) {
driver = "com.mysql.jdbc.driver";
url = "jdbc:mysql://localhost:3306/table";
}
// access
else if (mode.equals("access")) {
driver = "sun.jdbc.odbc.JdbcOdbcDriver";
url = "jdbc:odbc:table";
}
// db2
else if (mode.equals("db2")) {
driver = "com.ibm.db2.jdbc.app.db2driver";
url = "jdbc:db2://localhost:5000/table";
}
Connection con = null;
try {
Class.forName(driver)
.getInterfaces();
con = DriverManager.getConnection(url, user, password);
con.setAutoCommit(false);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
}
2009年11月19日 10:48