Chapter 17 . ODBC/JDBC 517 System.out.println( Connection established! ); DatabaseMetaData

Chapter 17 . ODBC/JDBC 517 System.out.println( Connection established! ); DatabaseMetaData dbmdata = con.getMetaData(); System.out.println( Database Information ); System.out.println( Database name: + dbmdata.getDatabaseProductName()) ; System.out.println( Version: + dbmdata.getDatabaseProductVersion()); System.out.println( Driver: + dbmdata.getDriverName()); System.out.println( Version: + dbmdata.getDriverVersion()); con.close(); } catch(SQLException ex) { System.err.println( SQLException: + ex.getMessage()); } } } Working with JDBC errors The main handler for errors with JDBC is SQLException class. SQLException, when invoked, sends a string with a description of the exception. This error message is retrieved with the getMessage()method. SQLException actually sends three pieces of information; in general terms, these are as follows: . Message string the message itself. . SQL state a five-character string retrieved with the getSQLState() method. . Vendor error code a code defined by the software vendor and retrieved with the getErrorCode()method. Testing for NULL values The wasNull() method serves to determine if a value returned from the database was NULL. The wasNull()method is called as part of the result set for a statement, as in the following example: Statement stmt = con.createStatement(); result = stmt.executeQuery(sql); while (result.next()) { if (result.wasNull()) { System.out.println( Null found. ); } }
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

Leave a Reply