Advertisement
Guest User

Untitled

a guest
Jan 29th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. select col1, col2, ... colN from table_name where col1 = ? ... ...
  2.  
  3. 0 -> TABLE_1
  4. 1 -> TABLE_2
  5. 2 -> TABLE_3
  6. ...
  7.  
  8. ...
  9. String usertypeCode = request.getParameter("usertype_code");
  10. String driver = ("com.mysql.jdbc.Driver");
  11. Class.forName(driver); // MySQL database connection
  12. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/ebooking" + "?user=user&password=user");
  13.  
  14. if (usertypeCode.equals("0") {
  15. usertype = "TABLE_0";
  16. } else if (usertypeCode.equals("1") {
  17. usertype = "TABLE_1";
  18. } else if (usertypeCode.equals("2") {
  19. usertype = "TABLE_2";
  20. } else {
  21. // handle invalid input
  22. }
  23.  
  24. PreparedStatement pst = conn.prepareStatement("Select * from ? where stu_username=? and stu_password=?");
  25. pst.setString(1, usertype);
  26. pst.setString(2, username);
  27. pst.setString(3, password);
  28. ResultSet rs = pst.executeQuery();
  29. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement