Advertisement
Guest User

Untitled

a guest
Mar 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package com.myapp.struts;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.SQLException;
  11. import java.sql.Statement;
  12.  
  13. /**
  14. *
  15. * @author 1337
  16. */
  17. public class ProductDAO {
  18. public void insertData(String orderNumber, String customerID ,
  19. String quantity, String shippingCost, String salesDate, String shippingDate) throws Exception {
  20. System.out.println("jdbc connection");
  21. Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
  22. Connection con = DriverManager.getConnection(
  23. "jdbc:derby://localhost:1527/myDatabase;user=mis320;password=mis320");
  24. try {
  25.  
  26. try {
  27. Statement st = con.createStatement();
  28. int value = st
  29. .executeUpdate("INSERT INTO PRODUCT (Order_Num,Customer_ID,Quantity,Shipping_cost,Sales_date,Shipping_date) VALUES('"
  30. + orderNumber
  31. + "','"
  32. + customerID
  33. + "','"
  34.  
  35. + quantity
  36. + "','"
  37. + shippingCost + "','" + salesDate + "','"+ shippingDate + "')");
  38. System.out.println("1 row affected" + value);
  39. } catch (SQLException ex) {
  40. System.out.println("SQL statement is not executed!" + ex);
  41. }
  42. con.close();
  43. } catch (Exception e) {
  44. e.printStackTrace();
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement