关于数据库添加语句问题

huxinxinxin 2012-04-12 08:12:17
Connection conn = DB.getconn();
String sql="insert into articles values (null,?,?,?,?,now(),?)";
PreparedStatement pstmt = DB.prepareStmt(conn, sql);
pstmt.setInt(1,"pid");
pstmt.setInt(2,"rootid");
pstmt.setString(3,"title");
pstmt.setString(4,"cont");
pstmt.setInt(5,0);
pstmt.excuteUpdate();
DB.close(pstmt);
DB.close(conn);
总是报这样的错误,
An error occurred at line: 16 in the jsp file: /replyDeal.jsp
Connection cannot be resolved to a type
13: String title=request.getParameter("title");
14: System.out.println("title");
15: String cont=request.getParameter("cont");
16: Connection conn = DB.getconn();
17: String sql="insert into articles values (null,?,?,?,?,now(),?)";
18: PreparedStatement pstmt = DB.prepareStmt(conn, sql);
19: pstmt.setInt(1,"pid");


An error occurred at line: 18 in the jsp file: /replyDeal.jsp
PreparedStatement cannot be resolved to a type
15: String cont=request.getParameter("cont");
16: Connection conn = DB.getconn();
17: String sql="insert into articles values (null,?,?,?,?,now(),?)";
18: PreparedStatement pstmt = DB.prepareStmt(conn, sql);
19: pstmt.setInt(1,"pid");
20: pstmt.setInt(2,"rootid");
21: pstmt.setString(3,"title");
唉,我菜鸟,求高手解答啊
...全文
157 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
huxinxinxin 2012-04-12
  • 打赏
  • 举报
回复
public static Connection getconn(){
Connection conn=null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bbs", "root" , "root");
} 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 = conn.prepareStatement(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return pstmt;
}

10,612

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧