我建了个通用Dao 是把ResultSet对象转换成Result对象的,但是,不知道为什么。在导入的时候,没有自动提示,我手动将其导入,却找不到Result这个对象。是不是应该下载个JAR包,放入lib下呢?请教大侠们。给我支支招。俺是菜鸟,在这里拜谢啦
package com.dao;
import java.sql.*;
import javax.servlet.jsp.jstl.sql.Result;
import javax.servlet.jsp.jstl.sql.ResultSupport;
public class BaseDao {
public static final String DRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
public static final String URL="jdbc:sqlserver://localhost:1433;DatabaseName=PublicizeWebPage";
public static final String USER="sa";
public static final String PWD="";
public Connection getConn(){
Connection conn=null;
try {
Class.forName(DRIVER);
conn=DriverManager.getConnection(URL,USER,PWD);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
public int executeUpdate(String sql,Object...param){
Connection conn=getConn();
PreparedStatement pst=null;
int row=0;
try {
pst=conn.prepareStatement(sql);
if(param!=null){
for(int i=0;i<param.length;i++){
pst.setObject(i+1, param[i]);
}
}
row=pst.executeUpdate();
pst.close();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return row;
}
public Result executeQuery(String sql,Object...param){
Connection conn =getConn();
PreparedStatement pst =null;
ResultSet rst =null;
Result rs = null;
try {
pst =conn.prepareStatement(sql);
if(param!=null){
for(int i=0;i<param.length;i++){
pst.setObject(i+1, param[i]);
}
}
rst =pst.executeQuery();
rs=ResultSupport.toResult(rst);
pst.close();
rst.close();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
}