JSP连接,查询,写入,修改SQL2005问题
来源:百度知道 编辑:UC知道 时间:2024/06/11 06:48:04
只要可以查询数据写入数据修改数据就可以了!
public class BaseDao {
private String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
private String url = "jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=books";
private String userName = "sa";
private String passWord = "sa";
protected Connection con;
protected PreparedStatement pstm;
protected ResultSet rs;
// 取得数据库连接
protected void getConnection() throws Exception {
Class.forName(driver);
con = DriverManager.getConnection(url, userName, passWord);
}
// 释放资源
protected void closeAll() {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (pstm != null) {
try {
pstm.close();
} catch (SQLException e) {
// TODO Auto-gene