|
-
March 11th, 2010, 02:28 AM
#1
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|