Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws IOException {
- // TODO code application logic here
- Logger logger = Logger.getLogger("MyLog");
- FileHandler fh;
- fh = new FileHandler("C:/Users/batam/Documents/MyLogFile.log");
- logger.addHandler(fh);
- SimpleFormatter formatter = new SimpleFormatter();
- fh.setFormatter(formatter);
- Class.forName("oracle.jdbc.driver.OracleDriver");
- Connection connection = null;
- try {
- connection = DriverManager.getConnection(
- "jdbc:oracle:thin:@capmtr10:1521/FINDATA1", "bamat",
- "fg_3002");
- } catch (SQLException e) {
- e.printStackTrace();
- return;
- }
- if (connection != null) {
- try {
- String sql = "select a.userid, a.Description from USER_FINANCE a where a.userid = 'batam'";
- Statement stmt = connection.createStatement();
- ResultSet rs = stmt.executeQuery(sql);
- while (rs.next()) {
- String id = rs.getString("userid");
- String name = rs.getString("Description");
- logger.info("Selecteds are : " + id + " : " + name);
- }
- rs.close();
- stmt.close();
- } catch (SQLException e) {
- logger.info("SQLException : " + e.getMessage());
- } finally {
- try {
- connection.close();
- } catch (SQLException ex) {
- Logger.getLogger(IFS.class.getName()).log(Level.SEVERE, null, ex);
- logger.info("Close Exception : " + ex.getMessage());
- }
- }
- } else {
- System.out.println("Failed to make connection!");
- logger.info("Failed to make connection!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement