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!
trulxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_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 Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.