我一直在处理一段简单的代码:
import java.sql.*;
class ODBC
{
MyConnection myCon;
Connection jdbcConnection;
ResultSet rs;
String sql;
PreparedStatement stmt;
public ODBC() throws Exception {
init();
}
public void init() throws Exception{
myCon = new MyConnection();
jdbcConnection = myCon.getConnection();
}
public void runQuery() throws SQLException {
sql = "SELECT DISTINCT HELPDESK_CASE.INCIDENT_NUMBER, "
+ "HPD_AUDIT.AUDIT_DATE, HPD_AUDIT.AUDIT_FIELD, "
+ "HELPDESK_CASE.DETAILED_DESCRIPTION, "
+ "HPD_AUDIT.AFTER_VALUE, "
+ "HELPDESK_CASE.DESCRIPTION "
+ "FROM HELPDESK_CASE INNER JOIN "
+ "HPD_AUDIT ON HELPDESK_CASE.INCIDENT_NUMBER "
+ "= HPD_AUDIT.INCIDENT_NUMBER "
+ "WHERE (((HELPDESK_CASE.INCIDENT_NUMBER)='INC001001837949') "
+ "AND ((HPD_AUDIT.AUDIT_FIELD)='Assigned Group')) "
+ "ORDER BY HELPDESK_CASE.INCIDENT_NUMBER, "
+ "HPD_AUDIT.AUDIT_DATE";
stmt = jdbcConnection.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE );
rs = stmt.executeQuery();
while(rs.next()){
System.out.println("Something is here");
}
}
public static void main (String args[]) throws Exception
{
ODBC odbc;
odbc = new ODBC();
odbc.runQuery();
}
class MyConnection {
public Connection getConnection() throws Exception
{
String URL = "jdbc:odbc:corpp05";
Connection c = DriverManager.getConnection(URL, "remro", "*****");
return c;
}
}
}
我无法弄清楚以下行为。
- 我使用相同的 JDBC 驱动程序在 MySQL 和 Access 中运行此查询,它们什么都不返回(因为它们应该返回 NOTHING,因为正在查询的事件编号不存在)。
- 我需要在这个程序的其他区域(在这个示例片段之外)能够调用resultSet.previous() resultSet.beforeFirst()等,因此需要能够向前和向后滚动。
当我使用preparedStatement如下:
stmt = jdbcConnection.prepareStatement(sql);
while 循环永远不会按预期行为执行,但是当我使用preparedStatement 时,如下所示:
stmt = jdbcConnection.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE );
(这是我需要的,因为我需要 TYPE_SCROLL_INSENSITIVE)while 循环被执行并且“Something is here”被打印出来。
我在这里想念什么?我觉得这是相对明显的,我需要退后一步,让其他人关注这一点,我相信。感谢帮助。
厘米