Guest User

Untitled

a guest
Dec 17th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. private Connection conn;
  2. private PreparedStatement pstmt;
  3. private ResultSet rs;
  4. private int rs2 = 0;
  5.  
  6. public UserDAO() {
  7. try {
  8. Class.forName("com.mysql.jdbc.Driver");
  9. conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ajax", "root", "!pretty124");
  10. // conn.setAutoCommit(false);
  11. } catch (Exception e) {
  12. e.printStackTrace();
  13. }
  14. }
  15.  
  16. void disconnect() {
  17. if (pstmt != null) {
  18. try {
  19. pstmt.close();
  20. } catch (SQLException e) {
  21. e.printStackTrace();
  22. }
  23. }
  24. if (conn != null) {
  25. try {
  26. conn.close();
  27. } catch (SQLException e) {
  28. e.printStackTrace();
  29. }
  30. }
  31. }
  32.  
  33. public String join_insert(String id, String pw, String name, String age, String gender, String hobby, String email,
  34. String phone) throws SQLException {
  35. String sql = "INSERT INTO test VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
  36. try {
  37. System.out.println("success.");
  38. pstmt = conn.prepareStatement(sql);
  39. pstmt.setString(1, id);
  40. pstmt.setString(2, pw);
  41. pstmt.setString(3, name);
  42. pstmt.setInt(4, Integer.parseInt(age));
  43. pstmt.setString(5, gender);
  44. pstmt.setString(6, hobby);
  45. pstmt.setString(7, email);
  46. pstmt.setString(8, phone);
  47.  
  48. rs2 = pstmt.executeUpdate();
  49. } catch (Exception e) {
  50. e.printStackTrace();
  51. return "";
  52. } finally {
  53. disconnect();
  54. }
  55.  
  56. return "";
  57. }
  58.  
  59. request.open("Post","./JoinInsertServlet?id="
  60. +encodeURIComponent(document.getElementById("join_info_id").value)
Add Comment
Please, Sign In to add comment