mano
Posts: 2
|
Posted: 04/11/2005, 9:25 PM |
|
HI,
I have a problem with JDBC , where i want to connect to a MSSQL Server 2000 Database stored in my local computer via a simple java class.And i have the required driver too but have a problem how to do it, Here's the code i use and this gives the following error message...
F:\j2sdk1.4.2_01\bin>javac Db.java
F:\j2sdk1.4.2_01\bin>java Db
Exception in thread "main" java.lang.NoClassDefFoundError: Db
I have already set the classpath to all the three jar files of the driver but this was the result! pls help me.. if there's any tutorials for this matter pls send the link too.
import java.sql.*;
public class Db {
public static void main(String[] args) {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection connection = DriverManager.getConnection("jdbc:odbc:MyDB");
if (connection != null) {
System.out.println();
System.out.println("Successfully connected");
System.out.println();
//String dbUrl = "jdbc:odbc:MyDB";
}
}catch(ClassNotFoundException e)
{System.err.println(e);}
catch (SQLException t)
{
System.err.println(t);}
}
}
when i use the code
"
DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());"
to get the connection it gave ....
F:\j2sdk1.4.2_01\bin>javac Db.java
Db.java:7: package com.microsoft.jdbc.sqlserver does not exist
DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerD
river());
^
1 error
_________________
Nothing without effort! |
|
|
|