SHARE
TWEET

Untitled

a guest May 22nd, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private List<BookModel> select(String[] params){
  2.           final String JDBC_DRIVER="com.mysql.jdbc.Driver";  
  3.           final String DB_URL="jdbc:mysql://localhost:3306/sys";
  4.           final String USER = "admin";
  5.           final String PASS = "1234";
  6.           Connection conn=null;
  7.           Statement stmt=null;
  8.          
  9.           List<BookModel> resultSet = new ArrayList<BookModel>();
  10.          
  11.           try{
  12.              Class.forName(JDBC_DRIVER);
  13.              conn = DriverManager.getConnection(DB_URL, USER, PASS);
  14.              stmt = conn.createStatement();
  15.              String sql;
  16.              sql = "SELECT * FROM book";
  17.              ResultSet rs = stmt.executeQuery(sql);
  18.              while(rs.next()){
  19.                  BookModel nextBook = new BookModel();      
  20.                 nextBook.isbn = rs.getString("isbn");
  21.                 nextBook.tytul = rs.getString("title");
  22.                 nextBook.autor = rs.getString("author");
  23.                 nextBook.wydawca = rs.getString("publisher");
  24.                 nextBook.data = rs.getString("date");
  25.                
  26.                 resultSet.add(nextBook);
  27.              }
  28.              rs.close();
  29.              stmt.close();
  30.              conn.close();
  31.              
  32.           }catch(SQLException se){
  33.              se.printStackTrace();
  34.           }catch(Exception e){
  35.              e.printStackTrace();
  36.           }finally{
  37.              try{
  38.                 if(stmt!=null)
  39.                    stmt.close();
  40.              }catch(SQLException se2){
  41.              }
  42.              try{
  43.                 if(conn!=null)
  44.                 conn.close();
  45.              }catch(SQLException se){
  46.                 se.printStackTrace();
  47.              }
  48.           }
  49.          
  50.           return resultSet;
  51.     }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top