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
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
Re: JDBC ClassNotFound Exception
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!
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