日期:2014-05-17 浏览次数:20768 次
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Conn {
private String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
private String URL="jdbc:sqlserver://localhost:1433;databaseName=Museum";
private String user="sa";
private String password="admin";
private String sql;
private Connection conn=null;
private Statement stmt=null;
private ResultSet rs=null;
public Conn(){
try {
Class.forName(driver);
conn=DriverManager.getConnection(URL, user, password);
stmt=conn.createStatement();
//System.out.println("成功");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String getSql() {
return sql;
}
public void setSql(String sql) throws SQLException {
this.sql = sql;
}
public ResultSet getRs() {
try {
rs=stmt.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public void setRs(ResultSet rs) {
this.rs = rs;
}
public void closeRs(){
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}