stat.executeQuery总是返回空值
下面的程序中,stat.executeQuery总是返回空值,我用Sql语句在pl\sql developer中执行,有返回值,不知道为啥?各位知道的帮忙看看吧,谢谢。
package oracleTest;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class TestJDBC
{
public static void main(String[] args)
{
Connection con=null;
String url="jdbc:oracle:thin:@10.1.69.173:1521:orclbi";
String user="ghb";
String password="123456";
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url, user, password);
Statement stat=con.createStatement();
ResultSet rs=stat.executeQuery("SELECT STATUS_ID FROM DIM.DIM_ULOAD_CONTROL WHERE OWNER = 'DIM' AND TABLE_NAME = 'DIM.DIM_BOOKINFO'");
int rowCount = 0;
System.out.println(rs.first() ? rs.getString(1) : "rs is null");
while(rs.next())
{
System.out.println(rs.getString(1));
rowCount++;
}
boolean isOk = false;
//isOk = (rs.getString(1).trim().equalsIgnoreCase("1")) ? true : false;
rs.close();
stat.close();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if (con != null)
{
con.close();
}
else
{
System.out.println("con is null");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
------解决方案--------------------System.out.println(rs.first() ? rs.getString(1) : "rs is null"); 这句去掉试试
------解决方案--------------------报错了/????
------解决方案--------------------应该是类型不对:
while(rs.next())
{
System.out.println(rs.getString(1));
rowCount++;
}
你的rs要是没有记录,就不会进while,应该是打印的这一句报错了,你看看是类型不对还是
空指针。要么是rs.getString(1)是null,要么就是rs的第一行不是String。看看异常信息。