Professional Documents
Culture Documents
TA Advanced Java JDBC-Eran Toch
TA Advanced Java JDBC-Eran Toch
• try block:
try {
System.out.println("Entering try statement");
out = new PrintWriter(new FileWriter("OutFile.txt"));
}
for (int i = 0; i < size; i++)
out.println("Value at: " + i + " = " + victor.elementAt(i));
Exception
MyException
MySpecificException2 MySpecificException1
} catch (Exception e) {
System.err.println("Exception caught: " + e.getMessage());
}
try {
System.out.println("Entering try statement");
out = new PrintWriter(
new FileWriter("OutFile.txt"));
for (int i = 0; i < size; i++)
out.println("Value at: " + i + " = " + victor.elementAt(i));
} catch (ArrayIndexOutOfBoundsException e) {
System.err.println("Caught ArrayIndexOutOfBoundsException: " +
e.getMessage());
} catch (IOException e) {
System.err.println("Caught IOException: " + e.getMessage());
} finally {
if (out != null) {
System.out.println("Closing PrintWriter");
out.close();
} else {
System.out.println("PrintWriter not open");
}
}
}
if (size == 0)
throw new EmptyStackException(“exception text”);
/**
* regular javadoc text…
* @throwsExceptionIf the Driver was not found.
* @throwsSQLExceptionIf the the <code>DriverManager.getConnection
* </code> method returned an error.
*/
public void createConnection()throws SQLException, Exception{
• Four stages:
– Install and configure the database
– Download and configure the JDBC
– Create a connection to the database
– Access the database
• In this tutorial, examples will be based on
MySQL. The reference section include a link
to instructions for MS Access.
Output
phones:
+972-4-9831894