我正在查询一个无法使用jdbc更改的现有表。我的sql server查询“select*from”返回结果,我用
logger.debug("Retrieved record firstname=" + rs.getString("FirstName"));
日志显示返回的数据,但也显示抛出了异常,因为该异常指示列名无效。
10:54:54.546 [main] DEBUG com.goprecise.ams.model.GetUserTest - Retrieved record firstname=System Account
10:54:54.754 [main] ERROR com.goprecise.ams.model.GetUserTest - The column name FirstName is not valid.
com.microsoft.sqlserver.jdbc.SQLServerException: The column name [FirstName] is not valid.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:234)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.findColumn(SQLServerResultSet.java:699)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getString(SQLServerResultSet.java:2525)
at com.goprecise.ams.model.GetUserTest.testJbpmOrganizationTableViaJdbc(GetUserTest.java:95)
列在表中,并且为记录中的字段显示了正确的值,那么为什么会引发关于它是无效列名的异常呢?如何纠正?”firstname”是定义为varchar且不为空的列的名称;不是使用jdbc为varchar返回一个字符串吗?围绕异常的代码(在上面显示的行中引发)是:
String sqlSelectUser = "SELECT TOP (5) * FROM " + helper.getUserDbTable();
try {
Connection conn = DriverManager.getConnection(helper.getJdbcUrl(), helper.getDbUsername(), helper.getDbPassword());
logger.info(sqlSelectUser);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sqlSelectUser);
rs.next();
logger.debug("Retrieved record firstname=" + rs.getString("FirstName"));
conn.close();
} catch (Exception e) {
暂无答案!
目前还没有任何答案,快来回答吧!