我从ojdbc getInt()得到了一个非常有趣的列号错误。
ps = conn.prepareStatement("select count(*) from tableA");
rs = ps.executeQuery();
int x;
if (rs.next())
x = rs.getInt(1);
ps = conn.prepareStatement("select count(*) as someVariable from tableA");
rs = ps.executeQuery();
int y;
if (rs.next())
y = rs.getInt(1);X和y的值不同。Y是我期望的正确数字。
我使用的是java 7和ojdbc6.jar (11.2.0.3.0)
谢谢。
发布于 2016-05-27 18:56:29
ps = conn.prepareStatement("select count(*) as someVariable from tableA");
ps = conn.prepareStatement("select count(*) as result from tableA");
rs = ps.executeQuery();
int x;
if (rs.next())
x = rs.getInt("result");
ps = conn.prepareStatement("select count(*) as someVariable from tableA");
rs = ps.executeQuery();
int y;
if (rs.next())
y = rs.getInt("someVariable");你没忘记rs.close(),conn.close(),statement.close()吗?使用资源进行尝试要比仅仅尝试要好。
try(Connection con = DriverManager.getConnection("DBpath","usr","pswd")) {
//doSomething
}在这种情况下,你不需要关闭它们,它们会自动关闭。注意:你只能用closeable对象来实现。
https://stackoverflow.com/questions/35205634
复制相似问题