0
votes

I'm trying to build a simple jdbc sql example. it's 1 class. I have both jdbc driver jars referenced it's runtime is JavaSE-1.6. It connects to a database I already have setup using this code...

// Load the JDBC driver
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        // Create a connection to the database

        connection = DriverManager
                .getConnection("jdbc:sqlserver://localhost:1433;database=AboardTestDB;integratedSecurity=true");
        System.out.println("Connected DB successfully");

        // STEP 4: Execute a query
        // writes the tables in local and not on GANESHN1\SQLSERVER2008
        System.out.println("Creating table in given database...");
        Statement stmt = connection.createStatement();

And the thing is it worked before. It worked beautifully. But a colleague of mine was having trouble with it. so I removed a jar to get the same error as him. but when I put it back it gave me this error message (again)

Dec 20, 2013 9:50:53 AM com.microsoft.sqlserver.jdbc.SQLServerConnection SEVERE: Java Runtime Environment (JRE) version 1.7 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0. Exception in thread "main" java.lang.UnsupportedOperationException: Java Runtime Environment (JRE) version 1.7 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0. at com.microsoft.sqlserver.jdbc.SQLServerConnection.(SQLServerConnection.java:304) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1011) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at sqldriver.doConnection(sqldriver.java:23) at sqldriver.main(sqldriver.java:59)

Everything else has stayed the same. I tried restarting, unstalling/reinstalling, creating a new project, trying different JRE's nothing.
Is there something I'm missing here? something else I can try?

1
Have you set your JDK compliance level to 1.6 (right click on project -> Properties -> Java Compiler)? - user1120144
Check the JRE tab of the run-configuration for your project. Maybe it has the "wrong" JDK/JRE set there. (But you really should be using the latest version of the JDBC driver.) - Ralf
oh, it's 1.6 alright. and I already tried changing the Execution environment (which is how I got it to work the first time) still nothing - wjhplano
How is this different from the question you asked two days ago how do I use different version of java And as I said then: you should only have sqljdbc4.jar on your classpath, even on Java 6! - Mark Rotteveel

1 Answers

0
votes

never mind! I got it working again by removing one of the jars. The thing is, I had them both in there and it was working just fine before :P Mysterious