Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. String query = "SELECT * FROM table WHERE UNIQUEID=? AND DIR IS NOT NULL AND NAME IS NOT NULL AND PAGETYPE IS NOT NULL";
  2. DBConnect Database = new DBConnect();
  3. Connection con = null;
  4. PreparedStatement ps = null;
  5. ResultSet rs=null;
  6. try {
  7. con = Database.getcon();
  8. ps = con.prepareStatement(query);
  9. ps.setString(1, URI);
  10. rs=ps.executeQuery();
  11. if(rs.next()){
  12. }
  13. } finally {
  14. if(ps != null)
  15. ps.close();
  16. if(rs != null)
  17. rs.close();
  18. if(con != null)
  19. con.close();
  20. }
  21. query = "SELECT COUNTCOMMENTS FROM videosinfos WHERE UNIQUEID=?";
  22. try {
  23. con = Database.getcon();
  24. ps = con.prepareStatement(query); // Getting error here
  25. rs=ps.executeQuery();
  26. ps.setString(1, URI);
  27. rs=ps.executeQuery();
  28. if(rs.next()){
  29. comments = rs.getInt(1);
  30. }
  31. ps.close();
  32. rs.close();
  33. con.close();
  34. } finally {
  35. if(ps != null)
  36. ps.close();
  37. if(rs != null)
  38. rs.close();
  39. if(con != null)
  40. con.close();
  41. }
  42.  
  43. public DBConnect(){
  44. try{
  45. Class.forName("com.mysql.jdbc.Driver");
  46.  
  47. String unicode="useSSL=false&autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8";
  48. con = DriverManager.getConnection("jdbc:mysql://localhost:15501/duckdb?"+unicode, "root", "_PWD");
  49. st = con.createStatement();
  50. }catch(Exception ex){
  51. System.out.println(ex.getMessage());
  52. System.out.println("couldn't connect!");
  53. }
  54. }
  55. public Connection getcon(){
  56. DBConnect condb = new DBConnect();
  57. Connection connect = con;
  58. return con;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement