Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jdbc

Status
Not open for further replies.

chz013

Programmer
Jan 5, 2003
73
0
0
US
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

import javax.swing.*;
import javax.swing.event.*;

import java.sql.*;

public class updateCronFiles {

public updateCronFiles() throws Exception
{
try {

System.out.println("Hi "); retrieveInformation();

} catch ( Throwable t ) {
System.out.println("problem ....");
t.printStackTrace();
}

}


protected void retrieveInformation() throws Exception {



Connection con;
String query, url;
int result;
Statement statement;

try {

try {

System.out.println("Connection..");

} catch (java.lang.ClassNotFoundException e ) {
System.out.println("JDBC Driver not found ... ");
throw ( e );
} // end of try

} catch ( SQLException sqlex ) {
sqlex.printStackTrace();
System.out.println("inside retrieveInformation in updateCronFiles class");
throw (sqlex);

} // end of catch

} // end of retrieveInformation

} // end of updateCronFiles class


But I keep getting compile error:

updateCronFiles.java:105: exception java.sql.SQLException is never thrown in body of corresponding try statement
} catch ( SQLException sqlex ) {
^
1 error


Any help is FULLY APPRECIATED.
 
Code:
import javax.swing.event.*;

import java.sql.*;    

public class updateCronFiles {

public updateCronFiles() // this is the last defense for Exception, don't throws Exception out
{
            try {
            
            System.out.println("Hi ");                
            retrieveInformation();
                        
            } catch ( Throwable t ) {
                System.out.println("problem ....");    
                t.printStackTrace();    
            }
            
}


protected void retrieveInformation() throws Exception {


    
    Connection con;
    String query, url;
    int result;
    Statement statement;
    
    
        try {
            // You should make the real connection and do the query within this block
            System.out.println("Connection..");
            int testing = 0;
            if (testing==1)
                throw new SQLException("testing2");
            else
                if (testing==2)
                   throw new ClassNotFoundException("testing");
            }    
            catch (java.lang.ClassNotFoundException e ) {
            System.out.println("JDBC Driver not found ... ");
            throw ( e );
            } 
            catch ( SQLException sqlex ) {
            sqlex.printStackTrace();
            System.out.println("inside retrieveInformation in updateCronFiles class");
            throw (sqlex);    
            } 
  }//end of retrieveInformation

public static void main(String args[])
       {
        new updateCronFiles();
       }
}// end of updateCronFiles class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top