SHARE
TWEET

Untitled

a guest Sep 20th, 2016 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Connection conn = null;
  2.     Statement stmt = null;
  3.     ResultSet rs = null;
  4.  
  5.     String jdbcUrl = "jdbc:sqlserver://localhost\SQLExpress:1433;DatabaseName=Movie;User=username;Password=password;";
  6.  
  7.     try {
  8.         Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  9.  
  10.         conn = DriverManager.getConnection(jdbcUrl);
  11.  
  12.         stmt = conn.createStatement();
  13.  
  14.         rs = stmt.executeQuery("SELECT TITLE FROM MOVIES;");
  15.         System.out.println(conn);
  16.  
  17.         if(rs.next()) {
  18.                 if(rs.getString(1).contentEquals("TEST")){
  19.                     flag = true;
  20.                 }else{
  21.                     flag = false;
  22.                 }
  23.         }
  24.  
  25.  
  26.     } catch (SQLException e) {
  27.         System.err.println("Unable to connect to database");
  28.         e.printStackTrace();
  29.     } catch (ClassNotFoundException e) {
  30.         System.err.println("Unable to load driver");
  31.         e.printStackTrace();
  32.     } finally {
  33.         try {
  34.             conn.close();
  35.             stmt.close();
  36.             rs.close();
  37.         } catch (SQLException e) {
  38.             e.printStackTrace();
  39.         }
  40.     }
  41.    
  42. System.out.println(conn);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top