0% found this document useful (0 votes)
24 views

Private Void Double: Txtid

This document describes how to edit data in a Java application. It allows the user to enter a product ID to display and edit the product's description and price. When the user clicks submit, it updates the database with the edited description and price, keeping the same product ID. The code uses JDBC to connect to an Access database and execute SQL queries to retrieve, display, and update the product data based on the ID entered by the user.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Private Void Double: Txtid

This document describes how to edit data in a Java application. It allows the user to enter a product ID to display and edit the product's description and price. When the user clicks submit, it updates the database with the edited description and price, keeping the same product ID. The code uses JDBC to connect to an Access database and execute SQL queries to retrieve, display, and update the product data based on the ID entered by the user.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

EDIT DATA

1. Show the data that is needed to Edit.


2. Change the data on price or product.

JFrame (Edit.java)

btnShowRecord will display the Product Description


and price of the product id entered on the txtID.

It will goes back to Menu.java

btnSubmit Will Submit the changes you’ve made on the Product Description and Price… the Product ID will
remains the same.

private void btnShowRecActionPerformed(java.awt.event.ActionEvent evt){

String id,des; double price;

id=txtID.getText();

try {

Connection kon;

ResultSet rs;

PreparedStatement stmt;

String url = "jdbc:odbc:konekted";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

kon = DriverManager.getConnection(url, "", "");

stmt = kon.prepareStatement("Select *from TblProducts WHERE PROID='"+id+"'");

rs = stmt.executeQuery();

if(rs.next())

des=rs.getString("Product");

price=rs.getDouble("Price"));

txtDes.setText(des);

txtPrice.setText(Double.toString(price));

else

JOptionPane.showMessageDialog(null,"No data Found","Commonwealth High


School",JOptionPane.WARNING_MESSAGE);

catch(Exception e){}}

}
private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {

String id,des;double price;

try {

id=txtUser.getText();

des=txtDes.getText();

price= Double.parseDouble(txtDes.getText());

Connection kon;

ResultSet rs;

Statement stmt;

String query;

String url = "jdbc:odbc:konekted";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

kon = DriverManager.getConnection(url, "", "");

stmt = kon.createStatement();

query = "UPDATE TblUsers SET Description='"+des+"', Price='"+price+"' WHERE PROID='"+id+"'";

int j = stmt.executeUpdate(query);

JOptionPane.showMessageDialog(null,"Successfully Updated "+j,"Commonwealth High


School",JOptionPane.INFORMATION_MESSAGE);

stmt.close();

kon.close();

} catch (Exception e) {

System.out.println(e);

You might also like