Advertisement
Guest User

Untitled

a guest
Jun 18th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. <%--
  2.     Document   : register
  3.     Created on : Jan 5, 2017, 11:38:31 PM
  4.     Author     : leetcat69
  5. --%>
  6.  
  7. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  8. <%@ page import="java.sql.*" %>
  9. <%
  10.     //Connection Database MySQL
  11.     Connection con = null;
  12.     PreparedStatement ps = null;
  13.     ResultSet rs = null;
  14.  
  15.     //Variables for connection database MySQL
  16.     String driverName = "com.mysql.jdbc.Driver";
  17.     String url = "jdbc:mysql://localhost:3306/lmsdb";
  18.     String user = "root";
  19.     String dbpsw = "";
  20.  
  21.     //Declare and collect the data from the form
  22.     String staffID,fullName,nric,department,mobilePhone,officePhone,staffType;
  23.     staffID = request.getParameter("staffID");
  24.     fullName = request.getParameter("fullName");
  25.     nric = request.getParameter("nric");
  26.     department = request.getParameter("department");
  27.     mobilePhone = request.getParameter("mobilePhone");
  28.     officePhone = request.getParameter("officePhone");
  29.     staffType = request.getParameter("staffType");
  30.    
  31.  
  32.     String sql = "INSERT INTO staff"
  33.             + "(staffID, fullName, nric, deptID, mobilePhone,officePhone,typeID) "
  34.             + "VALUES"
  35.             + "(" + staffID + ",'" + fullName + "'," + nric + ",'" + department + "'," + mobilePhone + ","+ officePhone +",'"+ staffType+"')";
  36.  
  37.     try {
  38.         Class.forName(driverName);
  39.         con = DriverManager.getConnection(url, user, dbpsw);
  40.         int action = con.createStatement().executeUpdate(sql);
  41.         con.setAutoCommit(true);
  42.  
  43.        
  44.         if (action >= 1) {
  45.             out.print("jadi");
  46.         }
  47.     }
  48.     catch(SQLException ex){
  49.         out.print(ex.getMessage());
  50.     }
  51. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement