|
-
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
-
March 11th, 2010, 08:07 AM
#2
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.
-
March 11th, 2010, 01:17 PM
#3
Re: JDBC ClassNotFound Exception
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!
-
July 3rd, 2010, 05:12 PM
#4
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!
-
July 12th, 2010, 02:09 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|