jsp + java + sqlserver在线系统源码
o 还是谢谢了
这个可以吗
package dataBase;
import java。sql。Connection;
import java。sql。DriverManager;
import java。sql。PreparedStatement;
import java。
sql。ResultSet;
//import java。sql。ResultSetMetaData;
import java。sql。SQLException;
import java。util。ArrayList;
import java。
util。List;
public class DBHelper {
private Connection con;
private PreparedStatement pstmt;
private ResultSet rs;
//静态语句块,加载驱动
static {
try {
rName("com。
microsoft。sqlserver。jdbc。SQLServerDriver");
} catch (ClassNotFoundException e) {
intStackTrace();
}
}
public ArrayList findBySql(String sql, ArrayList params, Class c) {
con = tCon();
try {
pstmt= epareStatement(sql);
doParams(pstmt, params);
rs=pstmt。
executeQuery();
while( xt()){
/**************************************************/
}
} catch (SQLException e) {
// TODO Auto-generated catch block
intStackTrace();
}
return List;
}
//连接数据库
public Connection getCon() {
try {
con = tConnection(
"jdbc:sqlserver:// ;databaseName=数据库名",
"连接数据库名", "密码");
} catch (SQLException e) {
intStackTrace();
}
return con;
}
//关闭所有连接
public void closeAll(ResultSet rs, PreparedStatement pstmt, Connection con) {
if (rs != null) {
try {
ose();
} catch (SQLException e) {
intStackTrace();
}
}
if (pstmt != null) {
try {
ose();
} catch (SQLException e) {
intStackTrace();
}
}
if (con != null) {
try {
ose();
} catch (SQLException e) {
intStackTrace();
}
}
}
//对数据进行增、删、改
// insert into xx values(?,?); params={"张三","a"};
public void doUpdate(String sql, List params) {
con = tCon();
try {
pstmt = epareStatement(sql);
doParams(pstmt, params);
pstmt。
executeUpdate();
} catch (SQLException e) {
intStackTrace();
} finally {
closeAll(null, pstmt, con);
}
}
public void doParams(PreparedStatement pstmt, List params)
throws SQLException {
if (pstmt != null && params != null && ze() > 0) {
for (int i = 0; i