Results 1 to 4 of 4
-
20th Jan 2011, 09:00 AM #1OPProbation
Need a Minor Help on Java
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..
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"); } }
Cool Aquarius? Reviewed by Cool Aquarius? on . Need a Minor Help on Java 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.. Rating: 5
-
20th Jan 2011, 04:18 PM #2Respected Member
try this:
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
Connection con=null;
PreparedStatement st;
Statement st1;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conriverManager.getConnection("jdbcdbc: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!");
ResultSet rs=st.executeQuery("select * from AddUser where UserId='"+UserId+"'");
if(rs.next())
{
}
else
{
JOptionPane.showMessageDialog(rootPane, "User not Available");
}
ResultSet 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");
}
}
-
20th Jan 2011, 05:50 PM #3OPProbation
its not working frnd
i hv done some editing..
now the query checks the existing book/user..
but now adding of data in the table is not occurring and updating that books table - available to not available!
Code:Connection con=null; PreparedStatement st1; Statement st2,st; ResultSet rs; String UserId=jTextField1.getText(); String B_Id=jTextField2.getText(); String date_issue=jTextField5.getText(); String due_date=jTextField6.getText(); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:LibraryIS"); Statement s=c.createStatement(); //st3=con.createStatement(); rs=s.executeQuery("select * from AddUser where UserId='"+UserId+"'"); if(rs.next()) { } else { JOptionPane.showMessageDialog(rootPane, "User not Available"); } rs=s.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+"'"); /* st1.executeUpdate("UPDATE IssueDetails SET UserId='"+UserId+"' where UserId='"+UserId+"'"); st1.executeUpdate("UPDATE IssueDetails SET Bks_Tkn='"+B_Id+"' where UserId='"+UserId+"'"); st1.executeUpdate("UPDATE IssueDetails SET date_issue='"+date_issue+"' where UserId='"+UserId+"'"); st1.executeUpdate("UPDATE IssueDetails SET due_date='"+due_date+"' where UserId='"+UserId+"'");*/ } else { JOptionPane.showMessageDialog(rootPane, "Book not Available"); } //st.executeUpdate("UPDATE Books SET Avail='Not Available' WHERE B_Id='"+b_id+"'"); } catch(Exception e) { System.out.println("Exception Raised1"+e); } try{ st1=con.prepareStatement("INSERT INTO IssueDetails(UserId, B_Id, date_issue, due_date) VALUES(?,?,?,?)"); st1.executeUpdate("UPDATE Books SET Avail='Not Available' WHERE B_Id='"+B_Id+"'"); st1.setString(1,UserId); st1.setString(2,B_Id); st1.setString(3,date_issue); st1.setString(4,due_date); st1.executeUpdate(); // st=con.createStatement(); JOptionPane.showMessageDialog(rootPane, "Book is issued to the user!"); } catch(Exception e) { System.out.println("Exception Raised2"); }
-
20th Jan 2011, 08:46 PM #4Respected Member
What you have above is not what I suggested. But ok.
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Java stinks: Turn off your Java browser plugin
By Loget in forum General DiscussionReplies: 37Last Post: 5th Sep 2012, 07:40 AM -
designer needed (pixel art minor work)
By immortalxx in forum Community CooperativeReplies: 0Last Post: 2nd Mar 2012, 12:33 AM -
Need help in JAVA
By digimon in forum Web Development AreaReplies: 10Last Post: 20th Jan 2012, 04:53 AM -
[Hiring] Need minor CSS & Wordpress Edits Paying Job
By LuDo8 in forum Completed TransactionsReplies: 7Last Post: 3rd Sep 2011, 09:29 PM -
Minor CSS Help needed.
By BlaZe in forum Web Development AreaReplies: 25Last Post: 2nd Jun 2011, 05:03 PM
themaCreator - create posts from...
Version 3.22 released. Open older version (or...