Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Beans > Java Programmin...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 1330 of 1372
Post > Topic >>

Java Programming: Advanced topics - Sample code

by Clive_S <cliveswan@[EMAIL PROTECTED] > Nov 16, 2007 at 04:04 AM

Hi,

I am trying to get a Java Bean sample code from Java Programming:
Advanced topics book working.
I have modified the code for SQL Server, it does not work??

The Java Virtual Machine throws a "could not find the main class"????
Could anyone point out what I am doing wrong.

I can get a db connection in a JSP page, am trying to create a
container that I can call the
variable from the JSP page.

Thanks for your help.

Clive

java.lang.NoClassDefFoundError: project1/DBdemo
Exception in thread main

package project1;

im****t java.sql.*;
/**
 * Class to create connection to a database and
 * and demonstrate basic SQL queries
 */
 public class DBdemo {
    /**
     * the connection object
     */
    static Connection connection = null;
    // select DB2 type 2 driver
    static final String dbDriver = "net.sourceforge.jtds.jdbc";
    static final String dbUrl = "jdbc:jtds:sqlserver://localhost:
1032/";
    // use the SKICLUB database
    static final String dbName = "Calibration";
    // set dbUser to any user on your Windows OS
    static final String dbUser = "userid";
    // set dbPassword to Windows password for dbUser
    static final String dbPassword = "password";
    /**
     * method to open the connection
     */
    public Connection getConnection() {
       if ( connection != null )
          return connection;
       try {
          connection = DriverManager.getConnection(
             dbUrl, dbUser, dbPassword );
       } catch( SQLException e ) {
          System.err.println("Cannot connect to database: for SQl
server, " + "check that SQl is running and  "  + "the SKICLUB database
exists." );
       }
       return connection;
    }

         public ResultSet getAllMemberInfo() {
                 ResultSet rs = null;
                 try {
                         Statement statement =
getConnection().createStatement();
                         String sql = "Select * from Prop1_Wallfinish,
Users where Prop1_Wallfinish.SurveyID= Users.SurveyIDS";
                         System.out.println( sql );
                         statement.executeQuery( sql );
                         rs = statement.getResultSet();
                 } catch( SQLException e ) {
                         System.out.println(
                                 "SQLException " + e.getMessage() );
                 } finally {
                         return rs;
                 }
         }

     public static void main(String[] args) {
            DBdemo dbdemo = new DBdemo();
            System.out.println("Getting Database driver" );
                try {
                         Class.forName( dbDriver );
                 } catch( ClassNotFoundException e ) {
                         System.err.println("Cannot load database
driver: for SQL, " + "your classpath must include " + "SQLLIB\\JAVA12\
\DB2JAVA.ZIP." );
                 }
                 System.out.println(
                         "Getting Database connection" );
                 Connection connection = dbdemo.getConnection();
                 if ( connection == null )
                         System.exit(0);
                 System.out.println( "Database ready" );
                 try {
                         // demonstrate a SELECT Statement
                         dbdemo.getAllMemberInfo();

                         connection.close();
                 } catch (Exception e) {
                         System.err.println(
                                 e.getClass().getName()  + ": " +
e.getMessage() );
                 }
    }// end public main

} // end DB
 




 3 Posts in Topic:
Java Programming: Advanced topics - Sample code
Clive_S <cliveswan@[EM  2007-11-16 04:04:45 
Re: Java Programming: Advanced topics - Sample code
Clive_S <cliveswan@[EM  2007-11-16 04:44:13 
Re: Java Programming: Advanced topics - Sample code
Clive_S <cliveswan@[EM  2007-11-16 15:29:01 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 22:55:17 CDT 2008.