Advertisement
Guest User

Untitled

a guest
Sep 21st, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. package com.flpi.serenity.steps.serenityLibrary;
  2. import java.sql.*;
  3.  
  4. import net.thucydides.core.steps.ScenarioSteps;
  5.  
  6. public class databaseInfo extends ScenarioSteps {
  7.        
  8.         // JDBC driver name and database URL
  9.         static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
  10.         static final String DB_URL = "jdbc:db2://10.77.0.95";
  11.        
  12.         //Database credentials
  13.         static final String USER = "dkidd";
  14.         static final String PASS = "Puppies13!";
  15.        
  16.         Connection conn = null;
  17.         Statement stmt = null;
  18.         {
  19.             try {
  20.             //Register JDBC driver
  21.             Class.forName("com.mysql.jdbc.Driver");
  22.            
  23.             //Open a connection
  24.             conn = DriverManager.getConnection(DB_URL,USER,PASS);
  25.            
  26.             //Execute a query
  27.             stmt = conn.createStatement();
  28.             String sql;
  29.             sql = "select * from member_sys.member where USERNAME = '270000006912';";
  30.             ResultSet rs = stmt.executeQuery(sql);
  31.         } catch(SQLException se) {
  32.             //Handle errors for JDBC
  33.             se.printStackTrace();
  34.         } catch(Exception e) {
  35.             //Handle errors for Class.forName
  36.             e.printStackTrace();
  37.         } finally {
  38.             //finally block used to close resources
  39.         try { if(stmt!=null)
  40.                 stmt.close();
  41.         } catch(SQLException se2) {
  42.             }
  43.         } try {
  44.             if(conn!=null)
  45.                 conn.close();
  46.         } catch(SQLException se1){
  47.             Throwable se = null;
  48.             se.printStackTrace();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement