Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Java, JDBC driver: Argh!

Java, JDBC driver: Argh!

Scheduled Pinned Locked Moved The Lounge
javadatabasesql-servercomsysadmin
12 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Sander RosselS Sander Rossel

    raddevus wrote:

    use Java to

    I found your problem! :D

    raddevus wrote:

    Java is so unsupported by anyone. X|

    How's that even possible? It's only been the most used language, according to TIOBE and the like, for about 25 years straight :~

    Best, Sander sanderrossel.com Migrating Applications to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

    R Offline
    R Offline
    raddevus
    wrote on last edited by
    #3

    Sander Rossel wrote:

    How's that even possible?

    The Internet is so clogged up with 25 years of Java documentation you can't find anything out here. It's all hopes and dreams of past generations, but nothing that actually works. :rolleyes:

    M 1 Reply Last reply
    0
    • R raddevus

      Sander Rossel wrote:

      How's that even possible?

      The Internet is so clogged up with 25 years of Java documentation you can't find anything out here. It's all hopes and dreams of past generations, but nothing that actually works. :rolleyes:

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #4

      ;P First time I've heard someone bitch about something being over supported.

      Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

      K R 2 Replies Last reply
      0
      • M Mycroft Holmes

        ;P First time I've heard someone bitch about something being over supported.

        Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

        K Offline
        K Offline
        kalberts
        wrote on last edited by
        #5

        The Internet version of "57 channels and nothing on"

        1 Reply Last reply
        0
        • R raddevus

          Just thought I might rant a bit. Simply trying to use MS example and driver to use Java to connect to sql server. The only error I can ever get is: java.sql.SQLException: No suitable driver found for jdbc:sqlserver:// I don't believe it is finding the proper jar file. I noticed that when I build via javac that even if I provide a bad path to the jar or whatever, the "compiler" happily rolls on. Oy! No way to even tell if javac is incorporating the jar. I've downloaded the jar from : Download Microsoft JDBC Driver for SQL Server - SQL Server | Microsoft Docs[^] I've tried older versions also. I'm running java 1.8 so I'm using the JDBC built for 1.8. Just wasting time and I can't tell why it is giving me the same bad error no matter what I try. So annoying! Waste of time! :mad: Java is so unsupported by anyone. X| I'm sure I'm doing something wrong. EDIT I noticed that it gave me two errors: at java.sql.DriverManager.getConnection(DriverManager.java:689) at java.sql.DriverManager.getConnection(DriverManager.java:270) I searched for source and found it at: DriverManager Java Source Code[^] -- don't know exactly which version that is and it doesn't have line numbers. THen I saw this....

          if(url == null) {
          throw new SQLException("The url cannot be null", "08001");
          }

          I set the connection string (url) to null and got that error. Now down below I see the other STUPID and NON-DETAILED error message:

          println("getConnection: no suitable driver found for "+ url);
          throw new SQLException("No suitable driver found for "+ url, "08001");

          J Offline
          J Offline
          Jon McKee
          wrote on last edited by
          #6

          Assuming the JAR is already added in your classpath, try adding Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); before the call to DriverManager.getConnection. I think that's still the full name of the SQL Server driver at least. Those are the two things that commonly cause this error. EDIT: Also if you're curious why javac doesn't seem to care, from what I understand it's because the SQLServerDriver class is never referenced in your code and therefore unnecessary for javac. DriverManager doesn't explicitly load driver classes, it just fetches them which is why you need to explicitly load the class via Class.forName.

          R 1 Reply Last reply
          0
          • M Mycroft Holmes

            ;P First time I've heard someone bitch about something being over supported.

            Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

            R Offline
            R Offline
            raddevus
            wrote on last edited by
            #7

            Mycroft Holmes wrote:

            First time I've heard someone bitch about something being over supported.

            I have an extreme talent for bitching and can do so about good or bad. :-\ :laugh:

            1 Reply Last reply
            0
            • J Jon McKee

              Assuming the JAR is already added in your classpath, try adding Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); before the call to DriverManager.getConnection. I think that's still the full name of the SQL Server driver at least. Those are the two things that commonly cause this error. EDIT: Also if you're curious why javac doesn't seem to care, from what I understand it's because the SQLServerDriver class is never referenced in your code and therefore unnecessary for javac. DriverManager doesn't explicitly load driver classes, it just fetches them which is why you need to explicitly load the class via Class.forName.

              R Offline
              R Offline
              raddevus
              wrote on last edited by
              #8

              Really great info. Thanks very much. It helps me confirm that I should have everything right. Here's the deal: My CLASSPATH is set to the directory where I'm building and the location of the mssql-jdbc-8.2.2.jre8.jar (downloaded from MS site). I can compile a program that has only the following in it:

              try{Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");}
              catch(Exception e1){System.out.println(e1);}

              When I run it, I see the following exception:

              java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver.class

              I thought I had the class name incorrect or something so I looked inside the jar (named aboe) and found the class. Maybe this jar is dependent upon another and that one isn't in the classpath or something?? I'm stumped!! Thanks again for the info.:thumbsup:

              J 1 Reply Last reply
              0
              • R raddevus

                Really great info. Thanks very much. It helps me confirm that I should have everything right. Here's the deal: My CLASSPATH is set to the directory where I'm building and the location of the mssql-jdbc-8.2.2.jre8.jar (downloaded from MS site). I can compile a program that has only the following in it:

                try{Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");}
                catch(Exception e1){System.out.println(e1);}

                When I run it, I see the following exception:

                java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver.class

                I thought I had the class name incorrect or something so I looked inside the jar (named aboe) and found the class. Maybe this jar is dependent upon another and that one isn't in the classpath or something?? I'm stumped!! Thanks again for the info.:thumbsup:

                J Offline
                J Offline
                Jon McKee
                wrote on last edited by
                #9

                I have the following example working. Hopefully it helps point you in the right direction. Folder structure:

                jdbctest

                • classes
                • lib
                  • mssql-jdbc-8.2.2.jre8.jar
                • src
                  • JDBCTest.java

                Files: JDBCTest.java

                import java.sql.Driver;
                import java.sql.DriverManager;

                public class JDBCTest {

                public static void main(String\[\] args)
                {
                    try
                    {
                        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                        Driver sqlServerDriver = DriverManager.getDriver("jdbc:sqlserver://localhost");
                        System.out.println(
                            sqlServerDriver.toString()
                            + ":" + sqlServerDriver.getMajorVersion()
                            + "." + sqlServerDriver.getMinorVersion()
                        );
                    }
                    catch (Exception ex)
                    {
                        System.out.println(ex.getMessage());
                    }
                } 
                

                }

                Commands (run from project directory):

                javac -d classes src/JDBCTest.java
                java -classpath classes:lib/* test.JDBCTest

                It should print out "SQLServerDriver:1:8.2".

                R 3 Replies Last reply
                0
                • J Jon McKee

                  I have the following example working. Hopefully it helps point you in the right direction. Folder structure:

                  jdbctest

                  • classes
                  • lib
                    • mssql-jdbc-8.2.2.jre8.jar
                  • src
                    • JDBCTest.java

                  Files: JDBCTest.java

                  import java.sql.Driver;
                  import java.sql.DriverManager;

                  public class JDBCTest {

                  public static void main(String\[\] args)
                  {
                      try
                      {
                          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                          Driver sqlServerDriver = DriverManager.getDriver("jdbc:sqlserver://localhost");
                          System.out.println(
                              sqlServerDriver.toString()
                              + ":" + sqlServerDriver.getMajorVersion()
                              + "." + sqlServerDriver.getMinorVersion()
                          );
                      }
                      catch (Exception ex)
                      {
                          System.out.println(ex.getMessage());
                      }
                  } 
                  

                  }

                  Commands (run from project directory):

                  javac -d classes src/JDBCTest.java
                  java -classpath classes:lib/* test.JDBCTest

                  It should print out "SQLServerDriver:1:8.2".

                  R Offline
                  R Offline
                  raddevus
                  wrote on last edited by
                  #10

                  Wow! That is a really great detailed example. Thanks so much.:thumbsup: I'm going to try it right now. I'll set it up exactly like yours and we will see what happens. Thanks again. I will let you know. :)

                  1 Reply Last reply
                  0
                  • J Jon McKee

                    I have the following example working. Hopefully it helps point you in the right direction. Folder structure:

                    jdbctest

                    • classes
                    • lib
                      • mssql-jdbc-8.2.2.jre8.jar
                    • src
                      • JDBCTest.java

                    Files: JDBCTest.java

                    import java.sql.Driver;
                    import java.sql.DriverManager;

                    public class JDBCTest {

                    public static void main(String\[\] args)
                    {
                        try
                        {
                            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                            Driver sqlServerDriver = DriverManager.getDriver("jdbc:sqlserver://localhost");
                            System.out.println(
                                sqlServerDriver.toString()
                                + ":" + sqlServerDriver.getMajorVersion()
                                + "." + sqlServerDriver.getMinorVersion()
                            );
                        }
                        catch (Exception ex)
                        {
                            System.out.println(ex.getMessage());
                        }
                    } 
                    

                    }

                    Commands (run from project directory):

                    javac -d classes src/JDBCTest.java
                    java -classpath classes:lib/* test.JDBCTest

                    It should print out "SQLServerDriver:1:8.2".

                    R Offline
                    R Offline
                    raddevus
                    wrote on last edited by
                    #11

                    I set up everything exactly the same as you showed, but I did have to alter a couple of things to get it working... When I ran java -classpath classes:lib/* test.JDBCTest from the project directory, I got an error that said:

                    Error: Could not find or load main class test.JDBCTest

                    If I run it successfully from the classes directory, it throws an exception that outputs:

                    com.microsoft.sqlserver.jdbc.SQLServerDriver

                    I believe the test.JDBCTest is not correct on the last line in your example, but I'm not sure. Seems like that would have it in a pkg named test, right? I'm hacking around but still don't quite have it. Thanks

                    1 Reply Last reply
                    0
                    • J Jon McKee

                      I have the following example working. Hopefully it helps point you in the right direction. Folder structure:

                      jdbctest

                      • classes
                      • lib
                        • mssql-jdbc-8.2.2.jre8.jar
                      • src
                        • JDBCTest.java

                      Files: JDBCTest.java

                      import java.sql.Driver;
                      import java.sql.DriverManager;

                      public class JDBCTest {

                      public static void main(String\[\] args)
                      {
                          try
                          {
                              Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                              Driver sqlServerDriver = DriverManager.getDriver("jdbc:sqlserver://localhost");
                              System.out.println(
                                  sqlServerDriver.toString()
                                  + ":" + sqlServerDriver.getMajorVersion()
                                  + "." + sqlServerDriver.getMinorVersion()
                              );
                          }
                          catch (Exception ex)
                          {
                              System.out.println(ex.getMessage());
                          }
                      } 
                      

                      }

                      Commands (run from project directory):

                      javac -d classes src/JDBCTest.java
                      java -classpath classes:lib/* test.JDBCTest

                      It should print out "SQLServerDriver:1:8.2".

                      R Offline
                      R Offline
                      raddevus
                      wrote on last edited by
                      #12

                      Wow!! I finally figured it out because I screwed around with -classpath so much!!. I'm on Windows so the separator has to be ; not a : Once I did that your instructions worked with the following java command:

                      java -classpath classes;lib/* JDBCTest

                      Notice I removed the test. (pkg name) and I changed the : to a ; While trying to get it working, I changed the output to have separate lines :

                      SQLServerDriver:1
                      8
                      2

                      Thanks so much, you got me there. Phew...

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups