SQLException 'general error' when using the JDBC-ODBC bridge

Hi folks,

There's a guy in my department who's trying to get to grips with JSPs and JDBC. He's written a test JSP accessing an Access database via the JDBC-ODBC bridge, but when he tries to run it, he gets an SQLException with the not very helpful error "general error".

The basic code is below:

<%

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con = DriverManager.getConnection("jdbc:odbc:Conference");

Statement stmt = con.createStatement();

String familyName = request.getParameter("required_familyname");

String firstName = request.getParameter("required_firstname");

String organization = request.getParameter("organisation");

String position = request.getParameter("position");

String email = request.getParameter("required_email");

String queryUpdatePerson="insert into Person values ('ITIL2002', '" + email +"','foo','" + familyName +"','" + firstName +"','" + organization +"','" + position +"' )";

int rowsAffectedPerson = stmt.executeUpdate(queryUpdatePerson);

if (rowsAffectedPerson == 1)

{

%>

<h1>Thank youfor expressing interest</h1>

<%}

else

{

%>

<h1>Sorry,addition has failed.Please,try later</h1>

<%

}

stmt.close();

con.close();

%>

The exception gets thrown on the executeUpdate() line, but the query is definitely correct. We've copied the line and tried executing it directly on Access as a query and it works fine.

The database definitely exists as an ODBC data source (a simple JSP to print out the contents of a table proved that).

We're running Tomcat 3.1 on Windows NT 4 Server with SP6a applied. I've tried posting on the JavaServer Pages forum without any joy, can anyone help?

Thanks very much in advance,

Raj.

[2560 byte] By [rajbhaskar] at [2007-9-26 3:18:14]
# 1
Have you tried SQLException.getNextException()?
jschell at 2007-6-29 11:32:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
I would add more validation. For instance, Is the connection executing successfully? Are the request.getParameter() returning null values? Can you execute a simple SELECT statement to test just the connection?-AJD
ajdiaz at 2007-6-29 11:32:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

I'm not sure what you mean by "successfully executing the connection". I've been doing some more work on this, and I've found that when I run Tomcat from the command line (I'm using WinNT4 Server), I can execute a select statement and get the 'general error' when I try the update, but when I run it as a service under NT (using JK_NT_Service), it can't find the data source. I've set the database up as an ODBC data source under the System DSN panel on a drive on our network.

Any ideas?

Thanks,

Raj.

rajbhaskar at 2007-6-29 11:32:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

Just some more information. Some of the problems that I was having were down to network problems. I've now moved the database to a local disk and updated the ODBC datasource appropriately. Now when I run Tomcat from the command line, the code gets executed once and then the JVM crashes. I'm guessing that this is a Bridge problem, but is there any way around it, other than to stop using it?

I've used the Bridge in the past on a Win95 machine and although I wouldn't exactly call it stable, it never behaved like this. In the extreme case, would it be possible to run the database on a Win95 machine on the network and access it from the server like that?

thanks,

Raj.

rajbhaskar at 2007-6-29 11:32:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

>I'm guessing that this is a Bridge problem

And I would guess not. I have run a large scale 24x7 enterprise system on the bridge and never traced a single problem down to odbc or the bridge.

It is more likely an environment problem.

Maybe something you installed overwrote the ODBC driver with an older version.

The most likely reason for not finding a DSN is becuase the DSN was created in the user rather than system space. And the next most likely reason is because of permissions problems - which can be fixed using regedt32 (not the same as regedit.)

If it was me I would stop trying to do everything at once (Tomcat, service and jdbc.)

First get it to work from the command line. Then get it to work in Tomcat. Then get it to work as a service.

jschell at 2007-6-29 11:32:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

> Maybe something you installed overwrote the ODBC driver with an older version.

How would I re-install the driver? (Sorry for such a simple question, but I'm really just finding my feet in system administration -- I'm a programmer, not a sysadmin :o).

> The most likely reason for not finding a DSN is becuase the DSN was created in the user rather

> than system space.

Nope, it's certainly in the system space. I double checked that.

> And the next most likely reason is because of permissions problems - which can be fixed using

> regedt32 (not the same as regedit.)

Again, stupid question -- how?

Thanks,

Raj.

rajbhaskar at 2007-6-29 11:32:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
A simple one:Have you tried to install the latest Microsoft Data Access Package (MDAC) that contains updated drivers?
brounar at 2007-6-29 11:32:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8
Fro regedt32, run it, find the DSN (and properties) right click on it (or the menu) for permissions. Make sure they are full open.
jschell at 2007-6-29 11:32:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...