CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2010
    Posts
    6

    JDBC ClassNotFound Exception

    Hi

    I am learning JDBC with MS SQL Server 2005. I wrote a simple code in Java 1.6
    This is my code in MainJdbc1.java

    import java.sql.*;

    public class MainJdbc1
    {
    public static void main(String[] argv) throws Exception
    {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=Vishal;password=");
    Statement st = con.createStatement();
    ResultSet res = st.executeQuery("SELECT * FROM student");
    while (res.next())
    {
    int i = res.getInt("roll");
    String s = res.getString("f_name");
    System.out.println(i + "\t\t" + s);
    }
    con.close();
    }
    }

    It executes perfectly after I set the classpath as "CLASSPATH =.;C:\Program Files\Microsoft SQL Server 2005 JDBC Driver\sqljdbc_1.0\enu\sqljdbc.jar"

    But today I am trying to execute this same code it is throwing an exception
    Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed. java.netConnectException: Connection refused: connect

    Thank you for any guidance

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: JDBC ClassNotFound Exception

    A ClassNotFound exception means the class mentioned in the error message is missing from your classpath.

    It's easy to cry "bug" when the truth is that you've got a complex system and sometimes it takes a while to get all the components to co-exist peacefully...
    D. Varga
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Jul 2005
    Location
    Currently in Mexico City
    Posts
    568

    Re: JDBC ClassNotFound Exception

    [remove]
    Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?

    I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)

    //always looking for job opportunities in AU/NZ/US/CA/Europe :P
    willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));

    USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!

  4. #4
    Join Date
    Jul 2010
    Posts
    6

    Re: JDBC ClassNotFound Exception

    you should add sql jdbc driver jar file to your project!

    I know an easier framework for jdbc named Jconnection! its a part of shine enterprise pattern!

    you can download and use it by the following link:

    http://sourceforge.net/projects/shine-enterpris/files/

    I bet you'll be excited!

  5. #5
    Join Date
    Jul 2010
    Posts
    17

    Re: JDBC ClassNotFound Exception

    I used Jconnection it help with JDBC and hibernate but his problem is to connection to database

    u must check the connection to your database

    and also you can use ODBC

    but jconnection make it easy to use JDBC

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured