Advertisement
Guest User

Untitled

a guest
Mar 10th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. String name = txtItem.getText();
  2. int qty = Integer.parseInt(txtQty.getText());
  3. int price = Integer.parseInt(txtPrice.getText());
  4. try {
  5. Class.forName("com.mysql.jdbc.Driver");
  6. con = DriverManager.getConnection("jdbc:mysql://localhost/supers","root","");
  7. pst = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
  8. String sql = "SELECT item,qty,price FROM stock";
  9. ResultSet rs = pst.executeQuery(sql);
  10.  
  11. if (rs.next())
  12. {
  13. name = rs.getString("item");
  14. qty = rs.getInt("qty");
  15. price = rs.getInt("price");
  16. txtItem.setText(name);
  17. txtQty.setText(String.valueOf(qty));
  18. txtPrice.setText(String.valueOf(price));
  19. }
  20. else
  21. {
  22. rs.previous();
  23. JOptionPane.showMessageDialog(this,"end of the file");
  24. }
  25.  
  26.  
  27. } catch (ClassNotFoundException ex) {
  28. Logger.getLogger(exmp.class.getName()).log(Level.SEVERE, null, ex);
  29. } catch (SQLException ex) {
  30. Logger.getLogger(exmp.class.getName()).log(Level.SEVERE, null, ex);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement