PrepareStatement报错,求助!

pinuocao2010 2010-01-14 09:05:13
有msbase.jar、mssqlserver.jar、msutil.jar三个包,用于连接数据库,且运行正常。
另一页面有<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*,java.util.*" errorPage="" %>来引入包,但是连接数据库的时候PrepareStatement pstmt=con.prepareStatement("select * from a where id=? "); 中PrepareStatement有红色下划线报错,提示:PrepareStatement cannot be resolved to a type.请大侠们指点。是缺少什么包么?
...全文
417 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
pinuocao2010 2010-01-15
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 a5692408b 的回复:]
public Admin adminLogin(String aname, String pwd) throws Exception {
Connection conn = null;
PreparedStatement pstm = null;
ResultSet rs = null;
Admin a = null;
try {
conn = JDBCUtil.getConnection();
conn.setAutoCommit(false);

String sql = "select * from admin where aname = ? and pwd = ?";
pstm = conn.prepareStatement(sql);
pstm.setString(1, aname);
pstm.setString(2, pwd);

rs = pstm.executeQuery();
if (rs.next()) {
a = new Admin(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5));
}
conn.commit();
return a;

} catch (Exception e) {
e.printStackTrace();
conn.rollback();
throw e;
} finally {
JDBCUtil.close(rs, pstm, conn);
}
[/Quote]
我这是一个带参数的跳转页面哦,动态获得id
pinuocao2010 2010-01-15
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 spring_cj 的回复:]
pstmt.setInt(1, 123);
[/Quote]
弱弱的问一句,这个代表啥意思?
a5692408b 2010-01-14
  • 打赏
  • 举报
回复
public Admin adminLogin(String aname, String pwd) throws Exception {
Connection conn = null;
PreparedStatement pstm = null;
ResultSet rs = null;
Admin a = null;
try {
conn = JDBCUtil.getConnection();
conn.setAutoCommit(false);

String sql = "select * from admin where aname = ? and pwd = ?";
pstm = conn.prepareStatement(sql);
pstm.setString(1, aname);
pstm.setString(2, pwd);

rs = pstm.executeQuery();
if (rs.next()) {
a = new Admin(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5));
}
conn.commit();
return a;

} catch (Exception e) {
e.printStackTrace();
conn.rollback();
throw e;
} finally {
JDBCUtil.close(rs, pstm, conn);
}
铁匠梁 2010-01-14
  • 打赏
  • 举报
回复
就这样注意检查
spring_cj 2010-01-14
  • 打赏
  • 举报
回复
pstmt.setInt(1, 123);
pinuocao2010 2010-01-14
  • 打赏
  • 举报
回复
谢谢啦!
spring_cj 2010-01-14
  • 打赏
  • 举报
回复
try{
PreparedStatement pstmt=con.prepareStatement("select * from dog where id=? ");
pstmt.setInt(1, "123");
ResultSet rs = pstmt.executeQuery();
if(rs.next()){
map.put(rs.getString("b"),"c.jsp?id="+rs.getString("id"));
}
}
finally{
con.close();
}
pinuocao2010 2010-01-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 spring_cj 的回复:]
PrepareStatement没有getString成员函数,ResultSet才有
[/Quote]

那该怎么改呀?ResultSet sqlRst=stat.prepareStatement("select * from a where id=? ");这样么?
xmykd 2010-01-14
  • 打赏
  • 举报
回复
可能是你的PrepareStatement 的包名称跟Connection的包名称不一样。把包名称写全了试试:
在它们前面添加java.sql.
spring_cj 2010-01-14
  • 打赏
  • 举报
回复
PrepareStatement没有getString成员函数,ResultSet才有
pinuocao2010 2010-01-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 spring_cj 的回复:]
PrepareStatement有红色下划线报错-》PrepareStatement改为PreparedStatement
[/Quote]

改完,map.put(pstmt.getString("b"),"c.jsp?id="+pstmt.getString("id")); 的getString有红色下划线了
spring_cj 2010-01-14
  • 打赏
  • 举报
回复
PrepareStatement有红色下划线报错-》PrepareStatement改为PreparedStatement
pinuocao2010 2010-01-14
  • 打赏
  • 举报
回复
能说详细点么?
PreparedStatement pstmt=con.prepareStatement("select * from dog where id=? ");
Map map=new HashMap();
map.put(pstmt.getString("b"),"c.jsp?id="+pstmt.getString("id"));
这是我接着的程序
spring_cj 2010-01-14
  • 打赏
  • 举报
回复
PreparedStatement
PrepareStatement

比较下区别

51,397

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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