Home » Developer & Programmer » JDeveloper, Java & XML » java exception
java exception [message #91005] Tue, 05 February 2002 12:49 Go to next message
sokeh
Messages: 77
Registered: August 2000
Member
Hello Java gurus!
I am an absolute newbie in this area and my first java problem is not going very well. I have written the below code but I am running into an exception -
Public class FirstCode must be defined in a file called "FirstCode.java". Please take a look at the code and tell me what is wrong and how to fix it.
Thanks in advance!
import java.sql.*;

public class FirstCode {

static String theJdbcDriverClass = "sun.jdbc.odbc.JdbcOdbcDriver";
static String theDatabaseUrl = "jdbc:odbc:EmpDB";
static String theUserName = "scott";
static String thePassword = "tiger";

public static void main( String args[[]] ) {

Connection myConnection = null;
Statement myStatement = null;
ResultSet myResult = null;

try {
// Load the JDBC driver
Class.forName( theJdbcDriverClass );

// Get a connection to the database
myConnection = DriverManager.getConnection(
theDatabaseUrl,
theUserName, thePassword );

// Create a statement to do some work
myStatement = myConnection.createStatement();

// execute a query and get a set of results
myResult = myStatement.executeQuery("SELECT * FROM EMP");

while( myResult.next() ) {
System.out.println("Name: " + myResult.getString("ENAME") );
System.out.println("Job: " + myResult.getString("JOB") );
System.out.println("");
}

}
catch( SQLException sqlError ) {
int cnt=1;
while( sqlError != null ) {
System.out.println( "Error " + cnt + ": " );
System.out.println( " SQLState: " + sqlError.getSQLState() );
System.out.println( " Message: " + sqlError.getMessage() );
System.out.println( " Vendor: " + sqlError.getErrorCode() );
System.out.println( "" );
sqlError = sqlError.getNextException ();
}
}
catch( Exception e ) {
e.printStackTrace();
}
finally {
try {
if( myResult != null ) { myResult.close(); }
if( myStatement != null ) { myStatement.close(); }
if( myConnection != null ) { myConnection.close(); }
}
catch( Exception e ) { e.printStackTrace(); }
}
}

}
Re: java exception [message #91007 is a reply to message #91005] Tue, 05 February 2002 18:34 Go to previous messageGo to next message
sokeh
Messages: 77
Registered: August 2000
Member
Oops!
I posted this response in the wrong thread.
I just wanted to say that I have figured this problem out.
Re: java exception [message #91401 is a reply to message #91005] Mon, 12 August 2002 21:29 Go to previous message
sini
Messages: 10
Registered: October 2001
Junior Member
Respected sir,

I want know different methos available to exceptions.
Previous Topic: Re: java.sql.SQLException: Io exception: End of TNS data channel
Next Topic: Re: ORA-01002 fetch out of sequence
Goto Forum:
  


Current Time: Fri Nov 22 19:42:43 CST 2024