【发布时间】:2011-04-01 05:55:54
【问题描述】:
import java.net.URL;
import java.net.URLConnection;
import java.sql.*;
public class searchlink{
public static void main(String args[]) throws Exception {
//String link="http://hosted.ap.org";
Connection con=null;
Statement stmt=null;
Statement stmtR=null;
if(con==null){
SQLConnection.setURL("jdbc:sqlserver://192.168.2.53\\SQL2005;user=sa;password=365media;DatabaseName=LN_ADWEEK");
con=SQLConnection.getNewConnection();
stmt=con.createStatement();
stmtR=con.createStatement();
}
ResultSet rs;
rs=stmt.executeQuery("select url from urls where url='http://www.topix.com/rty/elyria-oh'");
while(rs.next()){
String mem=rs.getString(1);
System.out.println("Result is "+mem);}
}
}
如果查询返回一行,上述程序将打印输出。 如果查询没有返回任何内容,程序将停止而不打印任何内容。
我希望程序能够识别查询没有返回任何内容,并打印出类似“SQL 查询执行后没有返回任何内容”的输出,而不是停止它而不打印任何内容。
如何使用一些方法或变量来识别查询已经执行而不返回任何行?
【问题讨论】: