Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- supplier supplierid(PK,AI),name,address,telephone
- item itemid(PK,AI),supplier_supplierID(FK),name
- try {
- String url ="jdbc:mysql://localhost/dbtec";
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection(url,userdb,pass);
- PreparedStatement statement = (PreparedStatement) conn.prepareStatement(" INSERT INTO supplier(name,address,telephone
- ) VALUES(?,?,?)");
- statement.setString(1,"stackoverflow");
- statement.setString(2,”15 newyork”);
- statement.setString(3,"+19898989");
- statement.executeUpdate();
- statement.close();
- /// Insert into another table
- PreparedStatement statement2= (PreparedStatement) conn.prepareStatement("INSERT INTO item(supplierID,name) VALUES (?,?) ");
- statement2.setString(1,"7");
- statement2.setString(2,"Bruce");
- statement2.executeUpdate();
- statement2.close();
- conn.close();
- }
- catch(SQLException e){
- e.printStackTrace();
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(newclient.class.getName()).log(Level.SEVERE, null, ex);
- }
Add Comment
Please, Sign In to add comment