#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Lisbon
    Posts
    45
    Rep Power
    13

    Arrow Java compile error-don't know how to extend class


    I'm trying to extend a class that implements an interface:
    : public class relationset extends org.gjt.mm.mysql.Driver

    class: org.gjt.mm.mysql.Driver
    interface: java.sql.Driver

    with the following Java code:
    PHP Code:
     import java.sql.*;
     
    import java.io.*;

    public class 
    relationset extends org.gjt.mm.mysql.Driver
    {
        public static 
    ResultSet execQuery() throws SQLException
        
    {
            try
            {
                
    Connection databaseConnection DriverManager.getConnection("jdbc:mysql://172.16.4.39:3306/ssntvjp""root""");

                
    String sqlString "SELECT * FROM Descriptor D WHERE D.SubDescriptor IS NULL";

                
    Statement stmt databaseConnection.createStatement();

                return 
    stmt.executeQuery(sqlString);
            }
            catch(
    SQLException e)
            {
                throw(
    e);
            }
        }

    ....but the following error occurs:

    .\relationset.java:7: unreported exception java.sql.SQLException; must be caught or declared to be thrown

    Can anybody tell-me what is wrong with this approah?

    Where's
    wally ?

    Irina/Lisbon/Portugal
  2. #2
  3. SwollenMember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    the master control
    Posts
    264
    Rep Power
    14
    you need to have more try blocks, and you tried to execute the query when it should be in a try block. i would use a ResultSet interface to get the results of your statement as well...might as well use the java.sql package plus there are a few other things that are wrong. anyway, this should clear up your troubles. also, i would suggest moving the connection attempt to a constructor somewhere. keep the java questions coming...

    try{

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

    Connection databaseConnection = DriverManager.getConnection("jdbc:mysql://172.16.4.39:3306/ssntvjp", "root", "");
    }
    catch(ClassNotFoundException cnfex){
    System.err.println("Failed to load JDBC/ODBC driver.");
    cnfex.printStackTrace();
    System.exit(1);
    }
    catch(SQLException sqlex){
    System.err.println("Unable to connect!");
    sqlex.printStackTrace();
    }
    try{
    String sqlString = "SELECT * FROM Descriptor D WHERE D.SubDescriptor IS NULL";
    ResultSet yourResults;

    Statement stmt = databaseConnection.createStatement();
    yourResults = stmt.executeQuery(sqlString);
    }
    catch(SQLException e){
    throw(e);
    }
    //something should be returned here
  4. #3
  5. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    India
    Posts
    7
    Rep Power
    0
    this error doesnt match ur code...it seems like u r runnin class file from the cache...try deleting and re-executing...
  6. #4
  7. SwollenMember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    the master control
    Posts
    264
    Rep Power
    14
    no...actually it does match the fact that you do not have try blocks.

IMN logo majestic logo threadwatch logo seochat tools logo