package cn.jbit.cms.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class BaseDao {
Connection con = null;
PreparedStatement ps = null;
public ResultSet rs=null;
private static final String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static final String url = "jdbc:sqlserver://localhost:1433;DatabaseName=SQLServer2008";
private static final String username = "sa";
private static final String pwd = "1";
public Connection getCon()throws Exception{
Class.forName(driver);
if(con==null||con.isClosed()){
con = DriverManager.getConnection(url, username, pwd);
}
return con;
}
//执行查询
public ResultSet executeQuery(String sql,Object... obje) throws Exception{
con=getCon();
ps=con.prepareStatement(sql);
for(int i=0;i<obje.length;i++){
ps.setObject(i+1, obje[i]);
}
rs=ps.executeQuery();
return rs;
}
//执行修改
public int execteUpdate(String sql,Object...object) throws Exception{
con=getCon();
ps=con.prepareStatement(sql);
ps.executeUpdate();
for(int i=0;i<object.length;i++){
ps.setObject(i+1, object[i]);
}
int count=ps.executeUpdate();
return count;
}
//执行增加
p
Java oop 第十一章 CMS
最新推荐文章于 2022-07-06 16:23:49 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)