SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    UK, London
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL error handling within javabeans

    ok.....im a beginner in both SQL and Java so bare with me please!!

    Im trying to get a javabean to access a DB2 database table. At the moment, im trying to work out how exceptions work, so that i can try and handle any possible error codes that come back when trying to update a table.

    the psuedocode for what im trying to do is :-

    EVALUATE SQLCODE

    WHEN CODE IS SUCCESSFUL
    continue
    WHEN END OF FILE
    move a value to the field
    WHEN OTHER
    then this is a error
    perform method x

    END-EVALUATE

    I know the first thing i need to do is catch the exception by using :-

    catch (SQLException e) {

    but then i get stuck!!....

    .......any ideas or any links to sites which explain exceptions would be gratefully received!
    If you can talk, you can sing, if you can walk, you can dance!!

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is what we have in our Java app accessing a DB2 database.

    Code:
    catch (SQLException ex)
    	{
    	// A SQLException was generated.  Catch it and
    	// display the error information.  Note that there
    	// could be multiple error objects chained together
     
    	System.out.println ("\n*** SQLException caught ***\n");
    	while (ex != null)
    		{
    		System.out.println ("SQLState: " + ex.getSQLState ());
    		System.out.println ("Message:  " + ex.getMessage ());
    		System.out.println ("Vendor:   " + ex.getErrorCode ());
    		ex = ex.getNextException ();
    
    		System.out.println ("");
    		}
    	} //end catch SQL Exception
    HTH,
    Kix

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    UK, London
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for your help kix.... :-)


    Whilst im here, Does anyone know where I can find a GOOD tutorial or information on exceptions and error handling within Java
    If you can talk, you can sing, if you can walk, you can dance!!


Bookmarks

Posting Permissions

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