Link to home
Start Free TrialLog in
Avatar of trulx
trulx

asked on

JDBC-ODBC error rexecuting but not debugging

Hi all,

I have this code to read an ACCESS database from a Java program:

try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String filename = "180.MDB";
            String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
            database+= filename.trim();

            con = DriverManager.getConnection(database ,"","");
           
            s = con.createStatement();
            s.execute("SELECT * from PROVINCIAS");
            ResultSet rs = s.getResultSet();

            if (rs != null)
            while (rs.next())

                {
                System.out.println("ID: " + rs.getString(1) + " CAS: " + rs.getString(2) + " EUS: " + rs.getString(3));
            }
        } catch (Exception e) {
            System.out.println("Error: " + e);
        }
            finally{
                  try {s.close();
                  con.close();
                  } catch (SQLException e) {
                        e.printStackTrace();
                  }
            }

When I run it with the debugger before it makes the connection and I go on step by step it makes everything perfect. Otherwise if I stop later or if I run it normally I've got this error:

#
# An unexpected error has been detected by Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d3f4df2, pid=2800, tid=2660
#
# Java VM: Java HotSpot(TM) Client VM (1.6.0_02-b06 mixed mode)
# Problematic frame:
# C  0x6d3f4df2
#
# An error report file with more information is saved as hs_err_pid2800.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#

Why is this happening? The truth is that while I was writting this we have proved in another computer and it works ok...

Any help will be welcome. Thanks in advance!
SOLUTION
Avatar of _ee
_ee

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trulx
trulx

ASKER

The prove I have made in the other computer was using the same Database with the same content. So I was wondering if the problem is the Java version (1.6 against 1.5) or a DLL or something else.

Thanks anyway _ee!
Avatar of mrcoffee365
_ee is right, it is likely to be a problem with your configuration on the machine where it doesn't work.  The fact that the code runs and makes a database connection on one machine does not mean that the second machine has access to the same database.

Have you looked at the output hs_err_pid2800.log mentioned in the error message?  That should give you more information about the problem.

Possible causes of not being able to make a connection on this machine are:
* the database isn't there
* the ODBC name is different from what you've put in the code (it's not 180.MDB)
* the user you are running as on this machine doesn't have permission to access the .mdb file

If you are asking if Java has changed between versions 1.5 and 1.6 to make your code not work, the answer is -- not to my knowledge.
Avatar of trulx

ASKER

I see what you mean, but:

*I have proved with local databases, copied from one computer to another. It's not in a shared place.
*180.MDB is the database name. I'm not using an ODBC connection (it's not made in the other computer
*I'm running in both computers as Administrator, and the local database has free access.

I'm stacked with this and seems to have a quite easy solution I can't find grrrrrrrrr

Thanks for your answers!
Avatar of trulx

ASKER

This is the most interesting part of the log archive:

Instructions: (pc=0x6d3f4df2)
0x6d3f4de2:  
[error occurred during error reporting, step 100, id 0xc0000005]

Stack: [0x00800000,0x00850000),  sp=0x0084f9a8,  free space=318k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  0x6d3f4df2
j  sun.jdbc.odbc.JdbcOdbc.driverConnect(J[B[B)V+0
j  sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JLjava/lang/String;)V+93
j  sun.jdbc.odbc.JdbcOdbcConnection.initialize(Ljava/lang/String;Ljava/util/Properties;I)V+984
j  sun.jdbc.odbc.JdbcOdbcDriver.connect(Ljava/lang/String;Ljava/util/Properties;)Ljava/sql/Connection;+129
j  java.sql.DriverManager.getConnection(Ljava/lang/String;Ljava/util/Properties;Ljava/lang/ClassLoader;)Ljava/sql/Connection;+210
j  java.sql.DriverManager.getConnection(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/Connection;+41
j  LeerBDCrearXML.leerBDCrearXML.main([Ljava/lang/String;)V+47
v  ~StubRoutines::call_stub

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  sun.jdbc.odbc.JdbcOdbc.driverConnect(J[B[B)V+0
j  sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JLjava/lang/String;)V+93
j  sun.jdbc.odbc.JdbcOdbcConnection.initialize(Ljava/lang/String;Ljava/util/Properties;I)V+984
j  sun.jdbc.odbc.JdbcOdbcDriver.connect(Ljava/lang/String;Ljava/util/Properties;)Ljava/sql/Connection;+129
j  java.sql.DriverManager.getConnection(Ljava/lang/String;Ljava/util/Properties;Ljava/lang/ClassLoader;)Ljava/sql/Connection;+210
j  java.sql.DriverManager.getConnection(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/Connection;+41
j  LeerBDCrearXML.leerBDCrearXML.main([Ljava/lang/String;)V+47
v  ~StubRoutines::call_stub

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x0aa2c000 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=3176]
  0x0aa27400 JavaThread "CompilerThread0" daemon [_thread_blocked, id=2616]
  0x0aa26000 JavaThread "Attach Listener" daemon [_thread_blocked, id=3172]
  0x0aa25400 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=3168]
  0x0aa17400 JavaThread "Finalizer" daemon [_thread_blocked, id=3152]
  0x0aa13000 JavaThread "Reference Handler" daemon [_thread_blocked, id=3124]
=>0x00776800 JavaThread "main" [_thread_in_native, id=3148]

I only can guess the same thing I guessed before during the debug: the problem is on the connection, isn't it?

Thanks!
You're right, you're using the database name.  However, you're not giving a path to the database.  Usually, in this case, you put something like c:/dir/180.mdb as the database name.  Maybe you copied the database to a different place relative to your running Java program, and that's why the  database connection can't find it.

You still haven't said if you've looked at the error output log -- it might be telling you that there's no such database, which would help in this debugging.
Sorry -- I didn't see your last post before sending my answer.  Yes, clearly the problem is the connection, which is what _ee said.  So get the location of the database, and put the full path to it in your code.
Avatar of trulx

ASKER

The path is not the problem. In the first moment I had a path written (cause I had the DB in another place).

Now I have this because I took the DB to the proyect path (I was testing if the problem was the DB path).

Now I'm thinking about using another JDBC connection. I will try with it tomorrow and I'll tell you.

Thanks!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trulx

ASKER

Today, when I arrived, it has worked the first time. Next times it crashes as always. At others computers it works always.

It only works debugging and stopping before connection and doing it step by step after it...

I will try yesterdays solution, another JDBC library.

Thanks!
Avatar of trulx

ASKER

It works perfect with the other JDBC Java Native Driver (HXTT ACCESS).

Thanks for your help!

See you!