Guest User

Untitled

a guest
Nov 27th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. supplier supplierid(PK,AI),name,address,telephone
  2. item itemid(PK,AI),supplier_supplierID(FK),name
  3.  
  4. try {
  5.  
  6.  
  7. String url ="jdbc:mysql://localhost/dbtec";
  8.  
  9. Class.forName("com.mysql.jdbc.Driver");
  10. conn = DriverManager.getConnection(url,userdb,pass);
  11.  
  12. PreparedStatement statement = (PreparedStatement) conn.prepareStatement(" INSERT INTO supplier(name,address,telephone
  13. ) VALUES(?,?,?)");
  14. statement.setString(1,"stackoverflow");
  15. statement.setString(2,”15 newyork”);
  16. statement.setString(3,"+19898989");
  17. statement.executeUpdate();
  18. statement.close();
  19.  
  20. /// Insert into another table
  21.  
  22. PreparedStatement statement2= (PreparedStatement) conn.prepareStatement("INSERT INTO item(supplierID,name) VALUES (?,?) ");
  23. statement2.setString(1,"7");
  24. statement2.setString(2,"Bruce");
  25. statement2.executeUpdate();
  26. statement2.close();
  27. conn.close();
  28. }
  29. catch(SQLException e){
  30. e.printStackTrace();
  31.  
  32. } catch (ClassNotFoundException ex) {
  33. Logger.getLogger(newclient.class.getName()).log(Level.SEVERE, null, ex);
  34. }
Add Comment
Please, Sign In to add comment