日期:2014-05-18  浏览次数:20630 次

PreparedStatement和类封装的问题,急!!!
import com.mysql.jdbc.PreparedStatement;
public class DB {
public static Connection getConn() {
Connection conn = null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bbs?user=root&&password=830401");
}catch (ClassNotFoundException e){
e.printStackTrace();
}catch (SQLException e) {
e.printStackTrace();
}
return conn;
}

public static PreparedStatement prepareStmt(Connection conn,String sql) {
PreparedStatement pstmt = null;
try {
///////// pstmt = (PreparedStatement) conn.prepareStatement(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return pstmt;
}
在jsp里没错,但封装了后必须加(PreparedStatement )的强制转换,为什么呀?
conn.prepareStatement(sql)的返回值就是PreparedStatement类型的呀



--------------------------------
以下内容为自动编辑的内容,并非楼主的发贴内容,此仅用于显示而已,并无任何其他特殊作用
楼主【bhy830401】截止到2008-08-05 01:52:33的历史汇总数据(不包括此帖):
发帖的总数量:0 发帖的总分数:0 每贴平均分数:0  
回帖的总数量:0 得分贴总数量:0 回帖的得分率:0%  
结贴的总数量:0 结贴的总分数:0  
无满意结贴数:0 无满意结贴分:0  
未结的帖子数:0 未结的总分数:0  
结贴的百分比:---------------------结分的百分比:---------------------
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=bhy830401

------解决方案--------------------
你导入的包是 com.mysql.jdbc.PreparedStatement
而 conn 可能是 java.sql.Connection