0% found this document useful (0 votes)
17 views1 page

Return

The document contains code to insert data into a database table and update another table when text fields are populated and a button is clicked, validating that an ID field is entered.

Uploaded by

Rezin Abdurahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Return

The document contains code to insert data into a database table and update another table when text fields are populated and a button is clicked, validating that an ID field is entered.

Uploaded by

Rezin Abdurahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

id =jTextField1.

getText();
name=jTextField2.getText();
admno=jTextField3.getText();
Student=jTextField4.getText();
Class=jTextField5.getText();
day=jTextField6.getText();
month=jTextField7.getText();
year=jTextField8.getText();
if(id=="")
JOptionPane.showMessageDialog(this,"Enter a Book Id");
else
{try {
Class.forName("java.sql.DriverManager");
Connection con=(Connection)

DriverManager.getConnection("jdbc:mysql://localhost:3306/Library","root","1234" );
Statement stmt=(Statement)con.createStatement();
String query1="Insert into history
values('"+id+"','"+name+"','"+Admno+"','"+Student+"','"+Class+"',null,'"+day+"-"+mo
nth+"-"+year+"');";
String query2="Update books set status='Available' where BookId='"+id+"';";
stmt.executeUpdate(query2);
ResultSet rs=stmt.executeUpdate(query1);}
catch(Exception e)
{

JOptionpane.showMessageDialog(this,e.getMessage());}JOptionPane.showMessageDialog(t
his,"Transaction recorded successfully")
}

You might also like