Created
March 13, 2011 16:24
-
-
Save jthoenes/868226 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
finally { | |
try { | |
if (resultSet != null) { | |
resultSet.close(); | |
} | |
} catch (SQLException ex) { | |
logger.error("Error in Database", ex); | |
} finally { | |
try { | |
if (statement != null) { | |
statement.close(); | |
} | |
} catch (SQLException ex) { | |
logger.error("Error in Database", ex); | |
} finally { | |
try { | |
if (conn != null) { | |
conn.close(); | |
} | |
} catch (SQLException ex) { | |
logger.error("Error in Database", ex); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void call() throws ReflectiveOperationException, IOException { | |
try { | |
callWithReflection(arg); | |
} catch (final Exception e) { | |
logger.trace("Exception in reflection", e); | |
throw e; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Integer>[] matrix = new List[23]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<integer>[] matrix = new List[23]; | |
List[] nonGenericMatrix = matrix; | |
// No exception | |
nonGenericMatrix[0] = Arrays.asList("String1", "String1"); | |
// java.lang.Integer cannot be cast to java.lang.String | |
List</integer><integer> vectorList = matrix[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Integer[] vector = new Integer[3]; | |
Object[] vectorObjects = vector; | |
// java.lang.ArrayStoreException | |
vectorObjects[0] = "String" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
callWithReflection(arg); | |
} catch (final ReflectiveOperationException | IOException e) { | |
throw new RuntimeException(e); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void readData() { | |
Connection conn = null; | |
Statement statement = null; | |
ResultSet resultSet = null; | |
try { | |
conn = DriverManager.getConnection(CONNECTION_STRING); | |
statement = conn.createStatement(); | |
resultSet = statement.executeQuery("SELECT patient, medication_day, medication_desc FROM medications"); | |
while (resultSet.next()) { | |
String patient = resultSet.getString("patient"); | |
LocalDate medication_day = LocalDate.fromDateFields(resultSet.getDate("medication_day")); | |
String medication_desc = resultSet.getString("medication_desc"); | |
System.out.println(String.format("'%s','%s','%s'", patient, medication_day, medication_desc)); | |
} | |
} catch (SQLException ex) { | |
logger.error("Error in Database", ex); | |
} finally { | |
try { | |
resultSet.close(); | |
statement.close(); | |
conn.close(); | |
} catch (SQLException ex) { | |
logger.error("Error in Database", ex); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
callWithReflection(arg); | |
} catch (NoSuchMethodException e) { | |
throw new RuntimeException(e); | |
} catch (IllegalAccessException e) { | |
throw new RuntimeException(e); | |
} catch (InvocationTargetException e) { | |
throw new RuntimeException(e); | |
} catch (ClassNotFoundException e) { | |
throw new RuntimeException(e); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
callWithReflection(arg); | |
} catch (ReflectiveOperationException e) { | |
throw new RuntimeException(e); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try (Connection conn = DriverManager.getConnection(CONNECTION_STRING); | |
Statement statement = conn.createStatement(); | |
ResultSet resultSet = statement.executeQuery("SELECT patient, medication_day, medication_desc FROM medications"); | |
BufferedWriter output = Files.newBufferedWriter(target, Charset.forName("utf-8"))) { | |
while (resultSet.next()) { | |
String patient = resultSet.getString("patient"); | |
LocalDate medication_day = LocalDate.fromDateFields(resultSet.getDate("medication_day")); | |
String medication_desc = resultSet.getString("medication_desc"); | |
output.write(String.format("'%s','%s','%s'\n", patient, medication_day, medication_desc)); | |
} | |
} catch (SQLException ex) { | |
logger.error("Error in Database", ex); | |
} catch (IOException ex) { | |
logger.error("Error in File Writing", ex); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment