Results 1 to 4 of 4

Thread: [RESOLVED] cant get java sql code to work, what does System.exit(); do?

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Resolved [RESOLVED] cant get java sql code to work, what does System.exit(); do?

    Hello

    I cant get this piece of java code to compile

    [code]
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.*;

    public class JDBCDemo {
    Connection db_connection;
    Statement db_statement;
    ResultSet result;

    public void loadDriver(){

    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    System.out.println ("+++++++++++++++++++");
    System.out.println ("+ database driver loaded +");
    System.out.println ("+++++++++++++++++++");
    } catch (Exception excep) {
    System.out.println ("Unable to load database driver: n" + excep);
    System.exit(0);
    }
    }

    public void connectToDB(){

    String dbName = "Business";
    String url = "jdbcdbc:" + dbName;

    try {
    db_connection = DriverManager.getConnection (url, "dba", "sql");
    System.out.println ("+++++++++++++++++++++++++++++++");
    System.out.println ("+ connected to database to DB + " + dbName);
    System.out.println ("+++++++++++++++++++++++++++++++");

    } catch (Exception excep) {
    System.out.println ("Unable to connect to database: n" + excep);
    System.exit(0);
    }
    }

    public void createStatement(){

    try {
    db_statement = db_connection.createStatement();
    System.out.println ("+++++++++++++++++++++");
    System.out.println ("+ statement created +");
    System.out.println ("+++++++++++++++++++++");
    } catch (Exception excep) {
    System.out.println ("Unable to create statement: n" + excep);
    System.exit(0);
    }
    }

    public void createTable(){

    String custTable =
    "CREATE TABLE tblCustomers (CustomerID INTEGER NOT NULL,[Name] TEXT(50) NOT NULL)";
    try {
    db_statement.executeUpdate(custTable);
    System.out.println ("+++++++++++++++++");
    System.out.println ("+ table created +");
    System.out.println ("+++++++++++++++++");
    } catch (Exception excep) {
    System.out.println ("Unable to create table: n" + excep);
    System.exit();

    }
    }


    }
    [/code}

    when i try to compile it, it comes up with the following error

    C:\JDBCApp>javac jdbcapp.java
    .\JDBCDemo.java:66: exit(int) in java.lang.System cannot be applied to ()
    System.exit();
    ^
    1 error

    if i actually comment out the following line of code, it works ok
    Code:
       System.exit();
    why am i getting the error, is the System.exit() essential?
    Last edited by vb_student; Dec 2nd, 2006 at 07:52 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width