Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String name = txtItem.getText();
- int qty = Integer.parseInt(txtQty.getText());
- int price = Integer.parseInt(txtPrice.getText());
- try {
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection("jdbc:mysql://localhost/supers","root","");
- pst = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
- String sql = "SELECT item,qty,price FROM stock";
- ResultSet rs = pst.executeQuery(sql);
- if (rs.next())
- {
- name = rs.getString("item");
- qty = rs.getInt("qty");
- price = rs.getInt("price");
- txtItem.setText(name);
- txtQty.setText(String.valueOf(qty));
- txtPrice.setText(String.valueOf(price));
- }
- else
- {
- rs.previous();
- JOptionPane.showMessageDialog(this,"end of the file");
- }
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(exmp.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(exmp.class.getName()).log(Level.SEVERE, null, ex);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement