Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%--
- Document : register
- Created on : Jan 5, 2017, 11:38:31 PM
- Author : leetcat69
- --%>
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <%@ page import="java.sql.*" %>
- <%
- //Connection Database MySQL
- Connection con = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- //Variables for connection database MySQL
- String driverName = "com.mysql.jdbc.Driver";
- String url = "jdbc:mysql://localhost:3306/lmsdb";
- String user = "root";
- String dbpsw = "";
- //Declare and collect the data from the form
- String staffID,fullName,nric,department,mobilePhone,officePhone,staffType;
- staffID = request.getParameter("staffID");
- fullName = request.getParameter("fullName");
- nric = request.getParameter("nric");
- department = request.getParameter("department");
- mobilePhone = request.getParameter("mobilePhone");
- officePhone = request.getParameter("officePhone");
- staffType = request.getParameter("staffType");
- String sql = "INSERT INTO staff"
- + "(staffID, fullName, nric, deptID, mobilePhone,officePhone,typeID) "
- + "VALUES"
- + "(" + staffID + ",'" + fullName + "'," + nric + ",'" + department + "'," + mobilePhone + ","+ officePhone +",'"+ staffType+"')";
- try {
- Class.forName(driverName);
- con = DriverManager.getConnection(url, user, dbpsw);
- int action = con.createStatement().executeUpdate(sql);
- con.setAutoCommit(true);
- if (action >= 1) {
- out.print("jadi");
- }
- }
- catch(SQLException ex){
- out.print(ex.getMessage());
- }
- %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement