some problem in JDBC operation

hi,

i have this problem i am new to JDBC and i wrote a sample program to try out , when i complied the program it compiled fine but when i ran the program

java progname

i got a class not defined error , below is my sample code

please can anybody tell me where the problem is

import java.sql.*;

public class JDBCTry

{

public static void main(String arg[])

{

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection DBconn = DriverManager.getConnection("jdbc:odbc:technical_library");

System.out.println("connected");

Statement st = DBconn.createStatement();

ResultSet rs = st.executeQuery("Select lastname,firstname from authors");

while(rs.next())

{

System.out.println(rs.getString("lastname"));

System.out.println(rs.getString("firsttname"));

System.out.println("\n");

}

}

catch(Exception e)

{

System.out.println(e);

}

}

}

regards

raghav

[1052 byte] By [raghav21] at [2007-9-26 2:01:46]
# 1
Posting the complete exception stack trace will help. Right ? Or is it that you do not get any stack trace ?
neville_sequeira at 2007-6-29 8:42:28 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

no the problem is that when i do

java JDBCTry i get a statement

error in main ClassNotDefined:JDBCTry

where can the problem be , i have checked my odbc setting , every thing is fine ,or is there any problem with the sun.jdbc.odbc.JdbcOdbcDriver

regards

Raghav

raghav21 at 2007-6-29 8:42:28 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
If it does not execute at all and gives you an error include your current directory (.)in the classpath set classpath=.;%classpath%
shirish_wagh at 2007-6-29 8:42:28 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

hi

can some body tell me what the problem can be , itried with jdk1.2 jdk1.3 every thing , when i run i get

classnotdefined error , is it a problem with my OS, i am running on win98 or the sun.jdbc.odbc.JdbcOdbcDriver is corrupted .because the error is caught in the

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver "); statement

is there any other way without using Class.forName()

thing

regards

raghav

raghav21 at 2007-6-29 8:42:28 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

How do you write it exactly?

in your first post:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

in your last post:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver ");

with a blank at the end of the string.

This would cause an exception.

Hartmut at 2007-6-29 8:42:28 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
ya thanks i got it . if we close the connection and resultset its working fine .regardsraghav
raghav21 at 2007-6-29 8:42:28 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...