Hi all, I am currently trying to do a simple test with:
on Windows 7 64-bit I'm following: http://dcx.sybase.com/index.html#1201/en/dbprogramming/jdbc-url-driver.html The error message I am getting is: SQLAnywhereAccessPoint: java.sql.SQLException: No suitable driver found for jdbc:ianywhere:dsn=MY_DSN I have verified the DSN with dbdsn -ls. I have placed: sajdbc4.jar and dbjdbc12.dll into C:Program FilesApache Software FoundationTomcat 7.0lib I have added sajdbc4.jar to the Eclipse project Build Path. When starting Tomcat, the dlls become locked. I've tried: conn = DriverManager.getConnection("jdbc:ianywhere:dsn=MSV_TEST_Central:uid=dba:pwd=sql"); conn = DriverManager.getConnection(driverConnectionURL, connDetails.getUsername(), connDetails.getPassword()); But I can't get it working. Any ideas? Thanks, Shao asked 17 Mar '14, 06:38 ShaoChan Breck Carter |
There appears to be a bug in Tomcat which requires even JDBC4 drivers to need to register the driver. There is a similar discussion on this topic involving a mySQL JDBC4 driver. Adding the following prior to the connection attempt should workaround the issue: DriverManager.registerDriver( (Driver) Class.forName( "sybase.jdbc4.sqlanywhere.IDriver").newInstance() ); answered 17 Mar '14, 14:43 Chris Keating Hi Chris, many thanks for that reply. I'll get that added and give it a go and report back! :) Cheers, Shao
(18 Mar '14, 04:17)
ShaoChan
Hi Chris. Thanks for that. I can confirm that that works. I'll do a bit more testing, but it's looking good! :) Cheers, Shao
(18 Mar '14, 04:58)
ShaoChan
Note that the driver is self registering so the Class.forName() should be sufficient without using registerDriver.
(18 Mar '14, 08:55)
Karim Khamis
|
Your URL header is incorrect. For sajdbc4.jar you need to use jdbc:sqlanywhere not jdbc:ianywhere. During the entire exchange above, Breck in particular has pointed to the sqlanywhere versus ianywhere distinction but all of you debug messages still say ianywhere. Please make sure you change the URL header to jdbc:sqlanywhere and properly rebuild your application. answered 17 Mar '14, 13:42 Karim Khamis Comment Text Removed
Hi Khamis. Sorry - a lot of the debug messages showing the connections get the driverConnectionURL variable which gets retrieved from the database which is wrong. But the code does use jdbc:sqlanywhere (as shown in the error) as I override it. I'll get it fixed in the database - I had changed it originally from it's original value of jdbc:odbc as from the Sybase docs it could be confused with something else.
(18 Mar '14, 04:21)
ShaoChan
|
Is the SQL Anywhere 4 JDBC driver in the JVM's class path?
Thanks Volker. I've added the CLASSPATH environment variable to point to the Apache Lib directory and restarted, but I have the same problem.
Please show us more of the code, including driverConnectionURL
Just as a hint:
You can add formatted code within comments simply by enclosing the code between a <PRE> and <\PRE> tag pair ... - way simpler than masking these tags here within my comment:)
The code shows "jdbc:ianywhere:dsn=MSV_TEST_Central" which does not agree with the error message you report: "No suitable driver found for jdbc:ianywhere:dsn=MY_DSN"
It also does not agree with the Help topic you point to, which shows "jdbc:sqlanywhere:DSN=SQL Anywhere 12 Demo"
Please show us the exact error message you get for the code you show, and please show us the exact contents of the DSN as it existed when the error message was produced.
Hi Breck, the MY_DSN is my fault. I started to substitute information for posting, but didn't see it through. The name of the DSN doesn't matter though and it is correct at MSV_TEST_Central and not confidential.
What about the second difference? ianywhere versus sqlanywhere?
Error log:
The Eclipse project runs only this like:
dbdsn -ls
That's a list of names. Please show us the contents of the DSN.
Also... should "ianywhere" be "sqlanywhere" like it says in the Help topic?
Changed to sqlanywhere. I must have made a mistake when subbing in the actual text rather than the driverConnectionURL.
What does happen when you use a non-existing DSN name in the getConnection() call, say "MSV_TEST_X" ? Does it lead to the same error message? (In other words: Is the DSN and its contents entry actually read and used, or is the DSN not found somehow?)
And besides that: Is the tomcat server running as a service (and would require a system DSN in contrast to a user DSN)? Note: System DSNs are not shared between 32-bit and 64-bit ODBC, they have to be created for the according registry hive separately... - As you have listed the system DSNs with "dbdns -ls", is that the result of the 64-bit dbdsn.exe?
Hi Volker. Yes, it seems to be the same.
Also Tomcat 7 states this:
https://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html
System — This class loader is normally initialized from the contents of the CLASSPATH environment variable. All such classes are visible to both Tomcat internal classes, and to web applications. However, the standard Tomcat startup scripts ($CATALINA_HOME/bin/catalina.sh or %CATALINA_HOME%bincatalina.bat) totally ignore the contents of the CLASSPATH environment variable itself, and instead build the System class loader from the following repositories:
Is that new on Tomcat 7? To ignore the CLASSPATH?
Then I would conclude the DSN is not really used. Does it exist as a 64-bit system DSN (listed with "%SQLANY12%\bin64\dbdsn -ls")?
What does happen when you omit the "DSN=..." and instead put in a normal connection string, say
And just a further question: Is the database engine already running?
As you try to connect via TCP/IP, that does not allow to auto-start a database engine AFAIK...Sorry, wrong statement, the TCPIP remark should not fit here as you do not include a LINKS connection parameter but a dbsrv12 -x command line option...
I did a dbdsn in the Bin64 directory and it shows.
In SQL Anywhere 12 everything we do is 64-bit.
Oops - I need to retest and put sqlanywhere back in.
Yes, the database is running.
I just want to double-check that anyone using SQL Anywhere sets up Tomcat as I have above. Basically, install all the software and put the various libraries in lib.
You can also put into WEB-INFlib of your own web app I believe.
However, the SQL Anywhere 12 documentation states to put the library in the CLASSPATH. I think it's just not picking up the library and possibly Tomcat ignores CLASSPATH anyway. But I can't find anything else in the documentation.
Have you tried copying the SQLAnywhere JDBC jar files into the $CATALINA_HOME/lib directory?
Hi Chris,
Yes, that's where I put them first. Then when not working, I looked into WEB_INFlib of application.
Also looked at modifying catalina.properties: shared.loader=$CATALINA_HOME/shared/lib and creating a new directory for a test.
But I can't get any of those working.
I am working on the assumption that the error message means that it hasn't loaded/found the library.
Thanks.
FWIW, we do use Tomcat (however, not Tomcat 7) with SQL Anywhere (however, with JConnect), and we've put the jodbc.jar in the WEB-INF\lib path. That works apparently. I can' tell whether this is the recommended approach, that's way beyond my expertise...
Thanks Volker. Our original application was running on Tomcat 6 and Java J2SE 6. However, at some customer sites, it started failing. I think it's because they upgraded the version of Java. Rather than go into the ins and outs of it, I decided to upgrade all components to the latest and to 64-bit and test with the latest EBF from SQL Anywhere. I am no expert in the Tomcat/java world. I was hoping there were others out there that have upgraded also and know what the solution is. Thanks.
@Shao: Though I am no Tomcat expert, either, I think this is more a Tomcat/JDBC issue than related to SQL Anywhere. A quick search on Stack Overflow on "JDBC Tomcat WEB/Inf 7 not found" lists a bunch of according questions with different JDBC drivers. Possibly there is one answer that can help you further.
(That doesn't mean your question will stay unanswered here - it's just me who has no further suggestions...)