Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. public boolean saveResearch(int userId, Filtre fltr){
  2. Connection conn = null;
  3. PreparedStatement stShop = null;
  4.  
  5. try{
  6. conn=getConnection();
  7. conn.setAutoCommit(false);
  8. stShop = conn.prepareStatement("insert into history set idclient=?,research=? "); //la requ�te
  9. stShop.setInt(1, userId) ;
  10. stShop.setString(2, fltr.getResearch());
  11.  
  12. stShop.executeUpdate();
  13. conn.commit();
  14.  
  15. } catch (BatchUpdateException e){
  16. System.out.println("Research is already in the database");
  17. return false;
  18. } catch (SQLException e){
  19. System.out.println("Error connecting to the database");
  20. e.printStackTrace();
  21. return false;
  22. } finally {
  23. if (stShop != null){
  24. try {
  25. stShop.close();
  26. } catch (Exception ex) {
  27. }
  28. }
  29. if (conn != null) {
  30. try {
  31. conn.close();
  32. } catch (Exception e) {
  33. }
  34. }
  35. }
  36. return true;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement