Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Control;
- import Model.Customer;
- import java.sql.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author Leconize
- */
- public class CustomerUtil {
- Connection conn;
- Statement state;
- public void init() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- String url = "jdbc:mysql://database.it.kmitl.ac.th:3306/it_33";
- String user = "it_33";
- String pwd = "uZf2Vnw3";
- conn = DriverManager.getConnection(url, user, pwd);
- state = conn.createStatement();
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(CustomerUtil.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(CustomerUtil.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public int addCustomer(Customer customer){
- String fname = customer.getFname();
- String lname = customer.getLname();
- String company = customer.getCompany();
- String mobile = customer.getMobile();
- String address = customer.getAddress();
- String email = customer.getEmail();
- String sqlCmd = "insert into Customers values('"+ fname + "','" + lname
- + "' , '" + company + "' , '" + mobile + "' , '" + email + "' , '" + address + "')";
- System.out.println(sqlCmd);
- int numberOfRowEffected = 0;
- try {
- numberOfRowEffected = state.executeUpdate(sqlCmd);
- } catch (SQLException ex) {
- Logger.getLogger(CustomerUtil.class.getName()).log(Level.SEVERE, null, ex);
- }
- return numberOfRowEffected;
- }
- public ResultSet loadData(){
- String sqlCmd = "select * from Customers;";
- ResultSet rs = null;
- try {
- rs = state.executeQuery(sqlCmd);
- } catch (SQLException ex) {
- Logger.getLogger(CustomerUtil.class.getName()).log(Level.SEVERE, null, ex);
- }
- return rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement