当前位置: 技术问答>java相关
绝对高分请教:关于记录集
来源: 互联网 发布时间:2015-08-11
本文导语: QueryString="SELECT * FROM GoodsInfo WHERE 商品条码='"+GoodsID+"'"; smt = con.createStatementResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); rs=smt.executeQuery(QueryString); 如果没有找到符合条件的纪录,怎样得知? | ...
QueryString="SELECT * FROM GoodsInfo WHERE 商品条码='"+GoodsID+"'";
smt = con.createStatementResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=smt.executeQuery(QueryString);
如果没有找到符合条件的纪录,怎样得知?
smt = con.createStatementResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=smt.executeQuery(QueryString);
如果没有找到符合条件的纪录,怎样得知?
|
if smt.nextnull then
...
else
...
else
|
设置异常处理啊
没有找到合适的记录,SQL自然规律回抛出一个异常,你扑获异常就可以了
没有找到合适的记录,SQL自然规律回抛出一个异常,你扑获异常就可以了
|
此时rs.next()==false
|
try
{
QueryString="SELECT * FROM GoodsInfo WHERE 商品条码='"+GoodsID+"'";
smt = con.createStatementResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=smt.executeQuery(QueryString);
while( rs.next() )
{
}
}
catch (Exception e)
{
System.out.println( "select: fail" + QueryString );
}
{
QueryString="SELECT * FROM GoodsInfo WHERE 商品条码='"+GoodsID+"'";
smt = con.createStatementResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=smt.executeQuery(QueryString);
while( rs.next() )
{
}
}
catch (Exception e)
{
System.out.println( "select: fail" + QueryString );
}
|
boolean noRecordFlag = true;//无记录标志
try
{
QueryString="SELECT * FROM GoodsInfo WHERE 商品条码='"+GoodsID+"'";
smt = con.createStatementResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=smt.executeQuery(QueryString);
while( rs.next() )
{
noRecordFlag = false;
}
}
catch (Exception e)
{
System.out.println( "select: fail" + QueryString );
}
if (noRecordFlag)
{
}
else
{
}
如果不怕麻烦就这样做。
try
{
QueryString="SELECT * FROM GoodsInfo WHERE 商品条码='"+GoodsID+"'";
smt = con.createStatementResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=smt.executeQuery(QueryString);
while( rs.next() )
{
noRecordFlag = false;
}
}
catch (Exception e)
{
System.out.println( "select: fail" + QueryString );
}
if (noRecordFlag)
{
}
else
{
}
如果不怕麻烦就这样做。