32

I know this is a basic question, but I can't seem to find an answer and I apologize, if this question is way too stupid, but here we go:

I am supposed to work with SQL Server (no problem so far) and with Java (love java, so no problem here either), but now: What am I supposed to do to make the combination work? I got: JRE 1.6 and the sqljdbc4.jar ... Before I put sqljdbc4.jar into my classpath I had sqljdbc.jar in it and with a test-program I got this exception:

21.08.2009 09:26:59 com.microsoft.sqlserver.jdbc.SQLServerConnection <init>
SCHWERWIEGEND: Die Java-Laufzeitumgebung (Java Runtime Environment, JRE), Version 1.6,
wird von diesem Treiber nicht unterstützt. Verwenden Sie die Klassenbibliothek 
'sqljdbc4.jar', die Unterstützung für JDBC 4.0 bietet.
java.lang.UnsupportedOperationException: Die Java-Laufzeitumgebung (Java Runtime 
Environment, JRE), Version 1.6, wird von diesem Treiber nicht unterstützt. Verwenden 
Sie die Klassenbibliothek 'sqljdbc4.jar', die Unterstützung für JDBC 4.0 bietet.
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.<init>(SQLServerConnection.java:223)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:840)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at msSqlTest.DB.dbConnect(DB.java:13)
    at msSqlTest.TestConnection.main(TestConnection.java:7)

Sorry for the German ... It basically means, that I should use sqljdbc4.jar, b/c the JRE I am using is not supported by the driver. So I put sqljdbc4.jar into my classpath, but it didn't work, so I am kinda lost, what I could do.

Maybe someone could tell be in an idiot-proof way what I should do :(

Oh yeah, here is the test appI use:

import java.sql.*;

public class TestConnection{
    public static void main(String[] args){
        // Neue DB und los geht's :)
        DB db = new DB();
        db.dbConnect("jdbc:sqlserver://localhost:1433/muff", "user", "pw" );
    }
}

class DB{
    public void dbConnect(  String db_connect_string, 
                            String db_userid, 
                            String db_password){
        try{
        Class.forName( "com.microsoft.sqlserver.jdbc.SQLServerDriver" );
            Connection conn = DriverManager.getConnection(
                            db_connect_string, 
                        db_userid, 
                        db_password);
            System.out.println( "connected" );
        }
        catch( Exception e ){
            e.printStackTrace();
        }
    }
};
abatishchev
  • 98,240
  • 88
  • 296
  • 433
doro
  • 785
  • 3
  • 11
  • 23

9 Answers9

28

Have you tried the jtds driver for SQLServer?

oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449
8

Do not put both the old sqljdbc.jar and the new sqljdbc4.jar in your classpath - this will make it (more or less) unpredictable which classes are being used, if both of those JARs contain classes with the same qualified names.

You said you put sqljdbc4.jar in your classpath - did you remove the old sqljdbc.jar from the classpath? You said "it didn't work", what does that mean exactly? Are you sure you don't still have the old JAR in your classpath somewhere (maybe not explicitly)?

Jesper
  • 202,709
  • 46
  • 318
  • 350
  • I think you'll find that whichever jar is in the classpath first will be favored (with the Sun JVM), although agreed, it's best to only include the jar you actually want to use. – Nick Holt Aug 21 '09 at 07:57
  • thnx for the reply. I didn't make it clear, sorry, but yes, I did remove the sqljdbc.jar from the classpath and put the sqljdbc4.jar into the classpath, but I still get the same exception. How can I see if it is still "not explicitly" in the classpath? – doro Aug 21 '09 at 07:57
  • With "not explicitly", I meant that maybe you are running code in a server (Tomcat for example) and you have the JAR in a lib directory of the server, or maybe it's even in your lib/ext directory of the JRE (JAR files in there are automatically put in the classpath). – Jesper Aug 21 '09 at 08:11
2

For anyone still googling this, go to \blackboard\config\tomcat\conf and in wrapper.conf put an extra line in wrapper.java.classpath pointing to the sqljdbc4.jar and then update the wrapper.conf.bb as well

Then restart the blackboard services and tomcat and it should work

It won't work by simply setting your java classpath, you have to set it up in the blackboard config files to point to your jar file with the jdbc library

2

The driver you are using is the MS SQL server 2008 driver (sqljdbc4.jar). As stated in the MSDN page it requires Java 6+ to work.

http://msdn.microsoft.com/en-us/library/ms378526.aspx

sqljdbc4.jar class library requires a Java Runtime Environment (JRE) of version 6.0 or later.

I'd suggest using the 2005 driver which I beleive is in (sqljdbc.jar) or as Oxbow_Lakes says try the jTDS driver (http://jtds.sourceforge.net/).

pjp
  • 17,039
  • 6
  • 33
  • 58
2

Maybe a little late, but using different drivers altogether is overkill for a case of user error:

db.dbConnect("jdbc:sqlserver://localhost:1433/muff", "user", "pw" );

should be either one of these:

db.dbConnect("jdbc:sqlserver://localhost\muff", "user", "pw" );

(using named pipe) or:

db.dbConnect("jdbc:sqlserver://localhost:1433", "user", "pw" );

using port number directly; you can leave out 1433 because it's the default port, leaving:

db.dbConnect("jdbc:sqlserver://localhost", "user", "pw" );
1

I had the same problem with a client of my company, the problem was that the driver sqljdbc4.jar, tries a convertion of character between the database and the driver. Each time that it did a request to the database, now you can imagine 650 connections concurrently, this did my sistem very very slow, for avoid this situation i add at the String of connection the following parameter:

 SendStringParametersAsUnicode=false, then te connection must be something like url="jdbc:sqlserver://IP:PORT;DatabaseName=DBNAME;SendStringParametersAsUnicode=false"

After that, the system is very very fast, as the users are very happy with the change, i hope my input be of same.

canadian_scholar
  • 1,315
  • 12
  • 26
0

If you are use sqljdbc4.jar, use the following code

ResultSet objResultSet = objPreparedStatement.getResultSet();
if (objResultSet == null) {
  boolean bResult = false;
  while (!bResult){
    if (objPreparedStatement.getMoreResults()){
      objResultSet = objPreparedStatement.getResultSet();
      bResult = true;
    }
  } 
}
objCachedRowSet = new CachedRowSetImpl();
objCachedRowSet.populate(objResultSet);
if (CommonUtility.isValidObject(objResultSet)) objResultSet.close();
objResultSet = null;
Himanshu
  • 31,810
  • 31
  • 111
  • 133
0

Indeed. The thing is that the 2008 R2 version is very tricky. The JTDs driver seems to work on some cases. In a certain server, the jTDS worked fine for an 2008 R2 instance. In another server, though, I had to use Microsoft's JBDC driver sqljdbc4.jar. But then, it would only work after setting the JRE environment to 1.6(or higher).

I used 1.5 for the other server, so I waisted a lot of time on this.

Tricky issue.

-1

What about the official JDBC 4.0 compatible JDBC driver from Microsoft?

  • 1
    Don't go near it, intentionally or not it's pretty poor or was the last time I used it - the conspiracy theorist in me might say that's intentional but I suspect they simple didn't devote enough resources to it... – Nick Holt Aug 21 '09 at 07:55