Home arrow static arrow Java Programming [Archive] - Exception in thread main
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Exception in thread main
This topic has 4 replies on 1 page.

Posts:66
Registered: 5/26/04
Exception in thread main  
Jun 19, 2004 8:02 AM



 
Hi,
I have written a small program to retrieve info from a database, but continue to get an error when running the code.
Exception in thread "main" Java.Lang.NoClassDefFoundError: TPMCConnection/class.
Please assist.

import java.sql.*; public class TPMCConnection {   public static void main (String args []) {     // declare Connection and Statement objects    Connection myConnection = null;    Statement myStatement = nulltry {       // register the Oracle JDBC drivers      DriverManager.registerDriver(        new oracle.jdbc.OracleDriver()      );       // create a Connection object, and connect to the database      // as scott using the Oracle JDBC Thin driver      myConnection = DriverManager.getConnection(        "jdbc:oracle:thin:@camdb1.crn.st.com:1521:camdb1",        "TPMCenter",        "TPMCenter"      );       // create a Statement object      myStatement = myConnection.createStatement();       // create a ResultSet object, and populate it with the      // result of a SELECT statement that retrieves the      // user and sysdate variables from the database via      // the dual table - the executeQuery() method of the      // Statement object is used to perform the SELECT      ResultSet myResultSet = myStatement.executeQuery(        "SELECT user, sysdate " +        "FROM dual"      );       // retrieve the row from the ResultSet using the      // next() method      myResultSet.next();       // retrieve the user from the row in the ResultSet using the      // getString() method      String user = myResultSet.getString("user");       // retrieve the sysdate from the row in the ResultSet using      // the getTimestamp() method      Timestamp currentDateTime =        myResultSet.getTimestamp("sysdate");       System.out.println("Hello " + user +        ", the current date and time is " + currentDateTime);       // close this ResultSet object using the close() method      myResultSet.close();     } catch (SQLException e) {       System.out.println("Error code = " + e.getErrorCode());      System.out.println("Error message = " + e.getMessage());     } finally {       try {         // close the Statement object using the close() method        if (myStatement != null) {          myStatement.close();        }         // close the Connection object using the close() method        if (myConnection != null) {          myConnection.close();        }       } catch (SQLException e) {         System.out.println("Error code = " + e.getErrorCode());        System.out.println("Error message = " + e.getMessage());       }     }   } // end of main() }


Re: Exception in thread main
Author: RockyFullen
In Reply To: Exception in thread main Jun 19, 2004 1:52 PM


Reply 1 of 3

OK, I got the program to work in Netbeans IDE, but when compiling in the terminal window, and running, I get the same error



Re: Exception in thread main
Author: duffymo
In Reply To: Exception in thread main Jun 19, 2004 1:55 PM

Reply 2 of 3

This suggests that you're missing a JAR in the CLASSPATH when you run on the command line that somehow you managed to get NetBeans to find for you. Check your CLASSPATH.

%



Re: Exception in thread main
Author: RockyFullen
In Reply To: Re: Exception in thread main Jun 19, 2004 2:51 PM

Reply 3 of 3

That is what it looks like but in the environment variables I have set
CLASSPATH = .;C:\OraHome9i\jdbc\lib\classes12.zip
This is also the classpath used in NetBeans.
any more ideas on what to look for?

 

Posts:11,200
Registered: 7/22/99
Re: Exception in thread main  
Jun 19, 2004 8:13 AM (reply 1 of 4)



 
The argument to "java" should be the name of the class that you want to run, not the name of the file you want to run.

The name of your class is "TPMCConnection" so you should run with "java TPMCConnection". The error message you are getting now says that the class "TPMCConnection.class" cannot be found, which makes sense because you don't have a class that has that name.
 

Posts:66
Registered: 5/26/04
Re: Exception in thread main  
Jun 19, 2004 8:46 AM (reply 2 of 4)



 
Its always the small things that we miss....
Thanks.
it worked
 

Posts:2
Registered: 7/9/04
Re: Exception in thread main  
Jul 9, 2004 3:03 AM (reply 3 of 4)



 
I have the same problem trying to connect to a database.
MY CLASSPATH
C:\j2sdk1.4.2_05\bin;C:\j2sdk1.4.2_05\lib;C:\j2sdk1.4.2_05\jre\bin;C:\j2sdk1.4.2_05\jre\lib;C:\j2sdk1.4.2_05\jre\lib\ext;C:j2sdk1.4.2_05\java;
The java file resides in java directory. My jar files in ext directory
 

Posts:11,200
Registered: 7/22/99
Re: Exception in thread main  
Jul 9, 2004 3:04 AM (reply 4 of 4)



 
...;C:j2sdk1.4.2_05\java;

there's a \ missing between C: and j2sdk
 
This topic has 4 replies on 1 page.