带参数的查询报错 Statemane.setint(1,cat_id)写道前面。赋值给sql^_^ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的写法有问题int cat_id = 0;String sql = "select * from catalog where catid=?";PreparedStatement pstmt = connection.prepareStatement(sql);pstmt.setInt(1,cat_id);ResultSet rs=pstmt.executeQuery(sql);..... statement.setInt(1);已经得到了所有的参数,再加一个cat_id可能不认识了,我理解的,不知道对否 对不起,是我写错了我的顺序是按后来大家所说的,报的错是"并非所有变量都已关联"如果按我最开始那个顺序,则报null错 从发程序:这个才是元程序 Connection connection=null; PreparedStatement statement = null; CatalogMsg m = new CatalogMsg(); try{ //String sql = "select * from catalog where catid="+cat_id; String sql = "select * from catalog where catid=?"; connection=jdbcMgr.getConnection(); statement=connection.prepareStatement(sql); statement.setInt(1,cat_id); ResultSet rs=statement.executeQuery(sql); if (rs.next()) { m.setCatID(rs.getInt("catid")); m.setParent(rs.getInt("parent")); m.setCatName(rs.getString("catName")); m.setCatDesc(rs.getString("catdesc")); m.setPos(rs.getInt("pos")); m.setCatDate(rs.getString("catDate")); } } 使用sonar check时出现的提示看不懂 java:如何在IE中直接打开office文件 求能用的 WebSocket 例子 jsp页面从actionform里读数据,怎么自动更新actionfomrm里的数据信息? 如何在网页中实现记住用户名和密码的功能? 请问大家进入公司的第一月都作什么? 一個session的問題?幫幫忙~! 高手请进来, 一个很奇怪的小问题??? 有没有能像vs.net开发asp那样支持托放组件的工具开发jsp? 在servlet中如何使用样式表? 大家如何处理服务器根目录问题,地址存在session,配置文件,还是自己创立的文件中? 中文显示问题!
int cat_id = 0;
String sql = "select * from catalog where catid=?";
PreparedStatement pstmt = connection.prepareStatement(sql);
pstmt.setInt(1,cat_id);
ResultSet rs=pstmt.executeQuery(sql);
.....
已经得到了所有的参数,再加一个cat_id可能不认识了,我理解的,不知道对否
PreparedStatement statement = null;
CatalogMsg m = new CatalogMsg();
try{
//String sql = "select * from catalog where catid="+cat_id;
String sql = "select * from catalog where catid=?";
connection=jdbcMgr.getConnection();
statement=connection.prepareStatement(sql);
statement.setInt(1,cat_id);
ResultSet rs=statement.executeQuery(sql);
if (rs.next())
{
m.setCatID(rs.getInt("catid"));
m.setParent(rs.getInt("parent"));
m.setCatName(rs.getString("catName"));
m.setCatDesc(rs.getString("catdesc"));
m.setPos(rs.getInt("pos"));
m.setCatDate(rs.getString("catDate"));
}
}