Activity Stream
48,167 MEMBERS
6989 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 4 of 4
  1.     
    #1
    Probation

    Unhappy 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

  2.   Sponsored Links

  3.     
    #2
    Respected 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");


    }


    }

  4.     
    #3
    Probation
    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");
            }

  5.     
    #4
    Respected Member
    What you have above is not what I suggested. But ok.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Java stinks: Turn off your Java browser plugin
    By Loget in forum General Discussion
    Replies: 37
    Last Post: 5th Sep 2012, 07:40 AM
  2. designer needed (pixel art minor work)
    By immortalxx in forum Community Cooperative
    Replies: 0
    Last Post: 2nd Mar 2012, 12:33 AM
  3. Need help in JAVA
    By digimon in forum Web Development Area
    Replies: 10
    Last Post: 20th Jan 2012, 04:53 AM
  4. [Hiring] Need minor CSS & Wordpress Edits Paying Job
    By LuDo8 in forum Completed Transactions
    Replies: 7
    Last Post: 3rd Sep 2011, 09:29 PM
  5. Minor CSS Help needed.
    By BlaZe in forum Web Development Area
    Replies: 25
    Last Post: 2nd Jun 2011, 05:03 PM

Tags for this Thread

BE SOCIAL