当前位置: 技术问答>java相关
求救:让我烦的简单问题 - jdbc,resultset
来源: 互联网 发布时间:2015-07-27
本文导语: 请各位高手看一看,是不是prepareStatement不能用select 选择两个表的字段 prepstm1=connection1.prepareStatement(" SELECT A.IM201,A.IM205 ,B.ST103 FROM IMLIBS.IMM2 A INNER JOIN SALIBS.SAMAMT B ON A.IM205=B.ST101 WHERE A.IM205='AB18' ",java.sql.Resu...
请各位高手看一看,是不是prepareStatement不能用select 选择两个表的字段
prepstm1=connection1.prepareStatement(" SELECT A.IM201,A.IM205 ,B.ST103 FROM IMLIBS.IMM2 A INNER JOIN SALIBS.SAMAMT B ON A.IM205=B.ST101 WHERE A.IM205='AB18' ",java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
rset1=prepstm1.executeQuery();
prepstm1=connection1.prepareStatement(" SELECT A.IM201,A.IM205 ,B.ST103 FROM IMLIBS.IMM2 A INNER JOIN SALIBS.SAMAMT B ON A.IM205=B.ST101 WHERE A.IM205='AB18' ",java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
rset1=prepstm1.executeQuery();
|
try:
prepstm1=connection1.prepareStatement(" SELECT A.IM201,A.IM205 ,B.ST103 FROM IMLIBS.IMM2 A INNER JOIN SALIBS.SAMAMT B ON A.IM205=B.ST101 WHERE A.IM205=? ",java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
prepstm1.setString(1,"AB18") ;
rset1=prepstm1.executeQuery();
prepstm1=connection1.prepareStatement(" SELECT A.IM201,A.IM205 ,B.ST103 FROM IMLIBS.IMM2 A INNER JOIN SALIBS.SAMAMT B ON A.IM205=B.ST101 WHERE A.IM205=? ",java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
prepstm1.setString(1,"AB18") ;
rset1=prepstm1.executeQuery();
|
应该用Statement替代prepareStatement
|
prepareStatement是让你可以先给出一个带参数的sql语句,再对参数赋值,进行sql操作.多用于多行记录的提交,查询,修改,删除,如查询是固定的sql语句的话,可以考虑用Statement.prepareStatement的用法如二楼所示,sql语句中使用?代表参数,再使用setString(1,string)等方法实现参数的赋值.executeQuery()或者executeUpdate()方法执行sql操作.具体用法,查查javadoc.