Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Connection conn;
- private PreparedStatement pstmt;
- private ResultSet rs;
- private int rs2 = 0;
- public UserDAO() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ajax", "root", "!pretty124");
- // conn.setAutoCommit(false);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- void disconnect() {
- if (pstmt != null) {
- try {
- pstmt.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- if (conn != null) {
- try {
- conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public String join_insert(String id, String pw, String name, String age, String gender, String hobby, String email,
- String phone) throws SQLException {
- String sql = "INSERT INTO test VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
- try {
- System.out.println("success.");
- pstmt = conn.prepareStatement(sql);
- pstmt.setString(1, id);
- pstmt.setString(2, pw);
- pstmt.setString(3, name);
- pstmt.setInt(4, Integer.parseInt(age));
- pstmt.setString(5, gender);
- pstmt.setString(6, hobby);
- pstmt.setString(7, email);
- pstmt.setString(8, phone);
- rs2 = pstmt.executeUpdate();
- } catch (Exception e) {
- e.printStackTrace();
- return "";
- } finally {
- disconnect();
- }
- return "";
- }
- request.open("Post","./JoinInsertServlet?id="
- +encodeURIComponent(document.getElementById("join_info_id").value)
Add Comment
Please, Sign In to add comment