Results 1 to 7 of 7
  1. #1
    bmuzammil is offline Member
    Join Date
    Nov 2014
    Posts
    4
    Rep Power
    0

    Exclamation Java netbeans ide - jdbc-odbc ms-sql database connection problem.

    hi, I have added all the resources below in attachments, check them if there's anything wrong.
    PROBLEM: The code is not working after reaching (Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); tried to post a message after but isn't working. I'm student and having serious problem with this database connection not working :( can't do anything with database related topics. if you have a working example, PLEASE! email me at: Bmuzammil@gmail.com or hotmail.com or here.

    THANK YOU ALL FOR YOU TIME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!~

    THIS IS THE CODE:
    or just download the .zip file I added and test it.
    Java Code:
     
    package myproject;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    public class MyProject {
        public static void main(String[] args) {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Connection c = DriverManager.getConnection("jdbc:odbc:conn", "sa", "123");
                Statement s = c.createStatement();
                ResultSet rs = s.executeQuery("select * from info");
                while (rs.next()) {
                    System.out.println(
                            rs.getInt(1) + " "
                            + rs.getString(2) + " "
                            + rs.getString(3) + " "
                            + rs.getInt(4) + " "
                            + rs.getString(5));
                }
            } catch (Exception e) {
            }
        }
    }
    Attached Files Attached Files

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Java netbeans ide - jdbc-odbc ms-sql database connection problem.

    Add a call to the printStackTrace() method in the catch{} block to print out the full text of any error message.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    bmuzammil is offline Member
    Join Date
    Nov 2014
    Posts
    4
    Rep Power
    0

    Default Re: Java netbeans ide - jdbc-odbc ms-sql database connection problem.

    run:
    java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 24)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 57)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:259)
    at myproject.MyProject.main(MyProject.java:12)
    BUILD SUCCESSFUL (total time: 11 seconds)

  4. #4
    bmuzammil is offline Member
    Join Date
    Nov 2014
    Posts
    4
    Rep Power
    0

    Default Re: Java netbeans ide - jdbc-odbc ms-sql database connection problem.

    I am using MS SQL Server 2014 & NetBeans IDE 8

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Java netbeans ide - jdbc-odbc ms-sql database connection problem.

    Then use the driver that comes with SQL Server.
    The JDBC/ODBC driver was never intended for general use, and isn't even in the latest versions of the JDK anymore.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    bmuzammil is offline Member
    Join Date
    Nov 2014
    Posts
    4
    Rep Power
    0

    Default Re: Java netbeans ide - jdbc-odbc ms-sql database connection problem.

    I am using MS SQL Server 2014 without tools sooooooooooo I think that's the problem :/ , I'll see if that fixes the problem. the same code is working fine in my Education Center that has SQLSERVER 2008 installed. I think that is the problem. Some tools are required.

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Java netbeans ide - jdbc-odbc ms-sql database connection problem.

    Get the MS SqlServer JDBC driver. For a more generic driver or if you're anti Microsoft, go for the jTDS driver.

    Forum service:
    - Microsoft JDBC Driver for SQL Server
    - jTDS JDBC Driver
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Replies: 0
    Last Post: 02-16-2011, 01:30 PM
  2. Replies: 2
    Last Post: 06-30-2010, 02:00 PM
  3. Replies: 4
    Last Post: 06-27-2010, 06:03 PM
  4. Help me this error in JDBC-ODBC connection
    By lordelf in forum Java Servlet
    Replies: 3
    Last Post: 04-04-2009, 08:37 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •