package test;
import java.sql.*;
public class DBC {
String url = "jdbc:odbc:test";
Connection conn;
public static DBC only;
public static DBC getInstence(){
if(only == null){
return new DBC();
}else{
return only;
}
}
public void getConnection(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(url);
} catch (SQLException ex) {
} catch (ClassNotFoundException ex) {
}
}
public void closeConnection(){
try {
conn.close();
} catch (SQLException ex) {
}
}
public boolean executeUpdate(String sql){
try {
getConnection();
Statement stmt = conn.createStatement();
closeConnection();
int i = stmt.executeUpdate(sql);
if (i > 0) {
return true;
} else {
return false;
}
} catch (SQLException ex) {
return false;
}
}
public ResultSet executeQuery(String sql){
try {
getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
return rs;
} catch (SQLException ex) {
return null;
}
}
}
» 除非另有声明,本站文章均为原创。
» 转载原创文章请以链接形式注明:
» 转载自:[Neeke] » [java-sql数据库连接公共类文件]
» 本文链接地址: http://www.ineeke.com/archives/58/
» 如果喜欢可以:点此邮件订阅或者点此阅读器订阅