Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC, orion server and SQL Server

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I am trying to connect to a SQL Server database using servlet, which is hosted by Orion Application Server (www.orionserver.com), Linux server.
And I hope someone will be able to help me !
After some debugging, I think that this is the part with problem:
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://ServerName ort", "username", "password");
}
catch (Exception e) {
System.err.println( e );
}
Actually I have the same error if I don't make the connection right now (just the line with Class.forName)
The Exception caught is:
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
After 2 days non-stop of working on this problem, I decided to make some java application, just in case of a driver problem (not in a servlet).
And it appears that everything is working fine.
So, I just made some Copy and Paste from my application for the connection part, and back in the Servlet, I have the same error !
I thought that maybe I had some problems with the classpath, so I added this line in the code:
System.out.println("Classpath: " + System.getProperty("java.class.path"));
And it appears that the jar archives with my driver are in the classpath.
So everything should work fine !!!
I tried exactly the same thing with a postgreSQL database that I am currently using, and I don't get any problem, all the connections are fine, and I can make my queries from the servlets .....
Does someone have some idea ??
Please let me know ....
Stephane.
BTW: I need to connect the SQL Server database for one and only one query .... And it's a remote database that I cannot convert.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stephane Cattet:
I thought that maybe I had some problems with the classpath, so I added this line in the code:
System.out.println("Classpath: " + System.getProperty("java.class.path"));
And it appears that the jar archives with my driver are in the classpath.
So everything should work fine !!!
No.
In an application server context, the CLASSPATH is often meaningless. In fact, orion.jar has its own Class-Path manifest entry and ignores the CLASSPATH completely. Put your jar in one of the following places:
  • The WEB-INF/lib directory of your web-application (usually preferred)
  • The orion/lib directory of the application server
  • The lib/ext directory of the Java runtime (discouraged)
  • HTH,
    - Peter
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, in my env variable I don't have any classpath .....
The CLASSPATH returned is the one automatically generated by the server itself (in orion.jar), it's needed to compile my servlets.
And I already tried to copy the jar in many locations, but I didn't tried under lib/ext yet!!
Today I already tried with another java version ....
I let you know I it works with the jar in the directory of the Java runtime.
Thanks,
Stephane.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, do you know a free jdbc driver for SQL Server ??
Thanks,
--Stephane.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
It's just to let you know that I solved my problem.
I think that maybe the microsoft jar file is corrupted or something like that, because I just extracted all the files and re-archived them and it's working !!
Bye,
--Stephane.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stephane Cattet:
BTW, do you know a free jdbc driver for SQL Server ??
Yes, FreeTDS is an open-source effort, ThinWeb FreeTDS is a commercially supported free driver. My experiences are not uniformly happy, though. I understand that Microsoft has just released a JDBC driver for SQL 2K based on the Merant driver.
Glad you solved your problem. But, in a J2EE environment the preferred way to access the database is using a DataSource bound in the JNDI tree. You configure the database into the application server (Orion: data-sources.xml). The application retrieves it from JNDI and uses it to get database connections. It's not only more flexible, it's also a lot faster (thanks to built-in connection pooling) and powerful (support for distributed transactions). And, if you've seen it once, it's no harder to use.
- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic