[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 413
  • Last Modified:

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!
0
trulx
Asked:
trulx
  • 6
  • 4
2 Solutions
 
_eeCommented:
Your problem seems to be with your Access call.  The reason that this doesn't show up during the debug stage, is because the Java program can't possibly know the contents of your database when compiling, but when running, the code causes an error inside the database.  This would also explain why it works on one computer, but not another.  Try looking through any database logs you have.
0
 
trulxAuthor Commented:
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!
0
 
mrcoffee365Commented:
_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.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
trulxAuthor Commented:
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!
0
 
trulxAuthor Commented:
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!
0
 
mrcoffee365Commented:
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.
0
 
mrcoffee365Commented:
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.
0
 
trulxAuthor Commented:
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!
0
 
mrcoffee365Commented:
All I can say is that in my testing with your code, with a properly defined path for the database, the code works.
0
 
trulxAuthor Commented:
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!
0
 
trulxAuthor Commented:
It works perfect with the other JDBC Java Native Driver (HXTT ACCESS).

Thanks for your help!

See you!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now