|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
package genconnection;
import java.sql.*;
public class GenConnection {
private static Connection con = null;
private static String db_url =
// "jdbc:mysql://localhost/long?user=root&password=test";
"jdbc:mysql://219.149.122.155/ctc02049?user=ctc02049&password=FpfkNPKk";
static {
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
} catch (Exception e) {
System.out.println(e.toString());
}
}
public GenConnection() {
}
public static Connection GetConnection() {
if (con != null) {
boolean isopen = false;
try {
isopen = con.isClosed();
} catch (Exception e) {
System.out.println(e.toString());
}
if (!isopen)return con;
}
try {
con = DriverManager.getConnection(db_url);
return con;
} catch (Exception e) {
return null;
}
}
// public static Connection GenConnection() throws ClassNotFoundException,
// IllegalAccessException, InstantiationException, SQLException {
// Class.forName("org.gjt.mm.mysql.Driver").newInstance();
// String url =
// "jdbc:mysql://219.149.122.155/ctc02049?user=ctc02049&password=FpfkNPKk";
// Connection conn = DriverManager.getConnection(url);
// return con;
// }
public static void Conclose() {
// if (con != null) {
// try {
// con.close();
// System.out.println("数据库已关闭");
// } catch (SQLException ex) {
// ex.printStackTrace();
// }
// }
}
}
|
|