Cool Aquariusâ„¢
New Member
gm..
i hv created different table for userdetails..
check the foll. code..
> the data is updated and working fine.
> but its not checking that existing user/book includes in the database or not..
i hv created different table for userdetails..
check the foll. code..
> the data is updated and working fine.
> but its not checking that existing user/book includes in the database or not..
Code:
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
Connection con=null;
PreparedStatement st;
Statement st1;
ResultSet rs;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:LibraryIS");
} catch(Exception e) {
System.out.println("Exception Raised1"+e);
}
try {
st=con.prepareStatement("INSERT INTO IssueDetails(UserId, B_Id, date_issue, due_date)
VALUES(?,?,?,?)");
//st.executeUpdate("UPDATE Books SET Avail='Not Available' WHERE B_Id='"+b_id+"'");
String UserId=jTextField1.getText();
String B_Id=jTextField2.getText();
String date_issue=jTextField5.getText();
String due_date=jTextField6.getText();
//String us_id=jTextField1.getText();
//String b_id=jTextField2.getText();
st.setString(1,UserId);
st.setString(2,B_Id);
st.setString(3,date_issue);
st.setString(4,due_date);
st.executeUpdate();
JOptionPane.showMessageDialog(rootPane, "Book is issued to the user!");
rs=st.executeQuery("select * from AddUser where UserId='"+UserId+"'");
if(rs.next())
{
}
else
{
JOptionPane.showMessageDialog(rootPane, "User not Available");
}
rs=st.executeQuery("select * from Books where B_Id='"+B_Id+"'");
if(rs.next())
{
st.executeUpdate("UPDATE Books SET Avail='Not Available' WHERE B_Id='"+B_Id+"'");
st.executeUpdate("UPDATE IssueDetails SET UserId='"+UserId+"' where UserId='"+UserId+"'");
st.executeUpdate("UPDATE IssueDetails SET Bks_Tkn='"+B_Id+"' where UserId='"+UserId+"'");
st.executeUpdate("UPDATE IssueDetails SET date_issue='"+date_issue+"' where UserId='"+UserId+"'");
st.executeUpdate("UPDATE IssueDetails SET due_date='"+due_date+"' where UserId='"+UserId+"'");
}
else
{
JOptionPane.showMessageDialog(rootPane, "Book not Available");
}
}
catch(SQLException e)
{
System.out.println("SQL Exception Raised1");
}
}