I am using a JSP page to connect to a Sybase DB using jConnect. It seems like I am able to connect to the DB but get a couple errors after connection. For some reason it works fine on my localhost using Netbeans but not on our Apache server. Here is my code below. I hope I put this in the correct forum.
//Step 3 - Create a statement object and obtain a ResultSet object stmt = conn.createStatement(); StringBuffer myquery = new StringBuffer(); myquery.append("select name, location"); myquery.append(" from location"); myquery.append(" order by name"); rs = stmt.executeQuery(myquery.toString()); }
It would be really helpful if you could post the output from your program, i.e. what the errors are. That helps us to identify where any problems in the code are more easily. You may also find using e.printStackTrace() more illuminating than just e on its own.
Secondly, please use the UBB CODE tags when posting code as otherwise all your indenting disappears and it's very hard to read.
Having said all that one problem I did notice is that in your catch blocks, you're catching exceptions that should cause processing to finish at that point (e.g. failed to connect, so shouldn't go and try to run the query now...; query failed, best not to look at the non-existant record set then).
Anyway, that probably won't solve your problem, but if you post again we may get there more quickly.
A couple of tips: You'd benefit from reading up on Java style conventions (e.g. don't use all CAPS for variables, that's constants and it's rarely a good idea to catch Exception, catch more specific exceptions - SQLException in this case).
One thing that I noticed is you need to close the ResultSet before you close the Statement. The Statement.close() implicitly closes the ResultSet also. So in your case you will get an errror if the ResultSet.close() is executed.
[ August 19, 2004: Message edited by: Martin Lira ]
[ August 19, 2004: Message edited by: Martin Lira ] [ August 19, 2004: Message edited by: Martin Lira ]
Joined: Aug 02, 2004
That's a very nasty problem you've got there - character set related. In case you can't decipher the conversation at the end of Martin's link and/or the error messages, the problem appears to be that your Sybase server is using a different character set to your client JVM, i.e. Cp850 (MSDOS Latin-1) and the JVM can't convert between the two. The linked thread is suggesting changing your default character set, but I don't know how to do that.
Anyway, as I can't help further I thought I'd give you some pointers as to how to lay out your code:
The comments saying which statements throw the exceptions are for your benefit only; that's not a convention. The stack trace will tell you exactly where in your code the exception occurs (class, method & line number). Notice that all processing is now in one try block so any checked exception will be caught and the finally block executed. No code we don't want to run will be reached afterwards.