2

Getting java.sql.SQLException

java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6986)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3110)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:253)
at com.test.Temp.main(Temp.java:29)

I am using following code

Connection con=null;
ResultSet rs=null;
Statement stmt=null;

try {
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  con=DriverManager.getConnection("jdbc:odbc:locator","locator","locator");

  stmt=con.createStatement();
  System.out.println("Before query");
  String query=null;
  query="select * from user_location_table";
  System.out.println("after query12");

  rs=stmt.executeQuery(query);
  //perform certain operation....
  rs.close();
  stmt.close();
  con.close();
} catch(Exception e) {
  e.printStackTrace();
}

The exception is thrown at stmt.executeQuery(query).

user_location_table contains following fields

user_id:number  not null,
latitude:number,
longitude:number,
update_time:timestamp(6)

Thanks in advance

1
  • This is likely due to an error when accessing the database. Does it happen consistently? Have you ensured the database connection details are correct? Commented Mar 25, 2012 at 0:35

2 Answers 2

5

I get it.

The error is thrown due to the use of datatype timestamp(6) in update_time.The exception is thrown whenever we try to execute the select statement containing a column with timestamp as the datatype.

Instead of the previous code we can use the following code for selecting

    query="select latitude,longitude,to_char(update_time,'HH24:MI:SS'),to_char(update,time,'DD-MON-YY') from user_location_table";    

This works fine,I have tested it.

Cheers!!

Sign up to request clarification or add additional context in comments.

1 Comment

You should use a real JDBC driver instead of the JDBC/ODBC bridge. Oracle's "native" JDBC does not have problems with a timestamp column. The JDBC/ODBC bridge is buggy (as you have just discovered) and slow.
0

A couple of thoughts. If it's only happening on the first execute, it may be that there is something invalid in the db and it's being compiled. Secondly, you may have something leaking because you aren't closing your connection and statement in a finally block. So if you get an exception, you aren't closing the connections and potentially you're creating a lock on your DB.

Add a finally block and move your close statements there checking for null:

try {
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  con=DriverManager.getConnection("jdbc:odbc:locator","locator","locator");

  stmt=con.createStatement();
  System.out.println("Before query");
  String query=null;
  query="select * from user_location_table";
  System.out.println("after query12");

  rs=stmt.executeQuery(query);
  //perform certain operation....

} catch (Exception e) {
  e.printStackTrace();
}
finally {
  try {
    if (rs!=null)
      rs.close();
  } catch (SQLException e) {
    e.printStackTrace();
  }
  try {
      if (stm!=null)
        stmt.close();
      } catch (SQLException e) {
      e.printStackTrace();
    }
  try {
    if (con!=null)
      con.close();
  } catch (SQLException e) {
    e.printStackTrace();
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.