I have a simple piece of code I have been working on :
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;
}
}
}
I cannot figure out the following behavior.
- I run this query in MySQL as well as Access using the same JDBC driver and they return nothing (as they should return NOTHING as the incident number being queried does not exist).
- I need the ability in other areas of this program (outside of this sample snip) to call resultSet.previous() resultSet.beforeFirst() etc. and therefor need to be able to SCROLL forwards and backwards.
-
When I use the preparedStatement as follows:
stmt = jdbcConnection.prepareStatement(sql);
The while loop is never executed as is expected behavior but when I use the preparedStatement as follows:
stmt = jdbcConnection.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE );
(Which I need since I need the TYPE_SCROLL_INSENSITIVE) The while loop IS executed and “Something is here” is printed.
What am I missing here? I feel like it is relatively obvious I need to just take a step back and have other eyes on this I believe. Appreciate the help.
Cmres
Download
thindriver from oracle site most suitable for the version of oracle that you are using. Add thatjarfile in the eclipse external jar files archive.After all set up is done:
you can make connection as follows:
Since
jdbc.getTransactionIsolation()returns 2 in your case so the possibility of dirty reads is eliminated.I hope changing driver would solve your problem.
EDIT
Read here about the
JDBC-ODBCdriver as postulated onOracleWebsite . After some line while describing aboutJDBC-ODBCdriver it tells the following cons:So it provides enough reason to believe that some critical issues might suffer when the application is solely based on
JDBC-ODBCdriver for implementing database transactions or other important database functionality via the sensitive API provided byjava.sqlpackage.