Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: My Java Ms Access Project is running successfully but it still has errors. Please help!

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default My Java Ms Access Project is running successfully but it still has errors. Please help!

    I am building a room management system in Java (Netbeans) and Ms Access. The jasper report is only showing code (source view) instead of design view. The GUI JFrame and Login JFrame are not displaying records in the database and the buttons are not working. Also the labels and text fields are not neatly arranged. The connection to the database is not displaying records. Please help me find out what is wrong with my code. Please only serious Java Programming experts should respond.

    Connection to the database. COIRMS.java

    package Login;
    import java.sql.*;
    public class COIRMS {
        Connection con;
        Statement st;
        ResultSet rs;
        public COIRMS ()
        {
            connect ();
        }
        public void connect () {
            try {
                String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
                Class.forName(driver);
                String COIRMS = "jdbc:odbc:COIRMS";
                con = DriverManager.getConnection(COIRMS);
                st = con.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
                String sql = ("select * from Room Reservations");
                rs = st.executeQuery(sql);
     
            }
     
        catch (Exception ex){
     
        }
        }
       public static void main (String [] args)
       {
        new COIRMS ();
    }
    }

    GUI JFrame code GUI.java

    package Login;
     
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import net.sf.jasperreports.view.*;
    import net.sf.jasperreports.engine.*;
     
     
    public class GUI extends COIRMS
    {
        JFrame f;
        JLabel RoomNumber;
        JLabel Firstname;
        JLabel Lastname;
        JLabel MobilePhoneNumber;
        JLabel EmailAddress; 
        JLabel RoomType;
        JLabel NoofAdults;
        JLabel NoofChildren;
        JLabel CheckInDate;
        JLabel CheckOutDate;
        JLabel ModeofPayment;
        JLabel AmountPaid; 
        JLabel AmountDue;
        JTextField t; 
        JTextField t1;  
        JTextField t2; 
        JTextField t3;     
        JTextField t4; 
        JTextField t5;  
        JTextField t6; 
        JTextField t7; 
        JTextField t8; 
        JTextField t9; 
        JTextField t10; 
        JTextField t11;   
        JTextField t12;
        JButton b1 = new JButton ("Next");
        JButton b2 = new JButton ("Previous");
        JButton b3 = new JButton ("Last");
        JButton b4 = new JButton ("First");
        JButton ud = new JButton ("Update");
        JButton del = new JButton ("Delete");
        JButton nr = new JButton ("New");
        JButton save = new JButton ("Save");
        JButton rep = new JButton ("Report");
     
        public GUI ()
        {
          frame ();
          btnAction();
     
    }
     public void frame ()
     {
      f = new JFrame();
      f.setVisible(true);
      f.setSize(2000,2000);
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    RoomNumber=new JLabel("Room Number");
    Firstname =new JLabel("First name"); 
    Lastname=new JLabel("Last name"); 
    MobilePhoneNumber =new JLabel("Mobile Phone Number"); 
    EmailAddress =new JLabel("Email Address");
    RoomType =new JLabel("Room Type"); 
    NoofAdults =new JLabel("No of Adults");  
    NoofChildren  =new JLabel(" No of Children");
    CheckInDate =new JLabel("Check In Date");
    CheckOutDate   =new JLabel("Check Out Date"); 
    ModeofPayment =new JLabel("Mode of Payment"); 
    AmountPaid =new JLabel("Amount Paid"); 
    AmountDue =new JLabel("Amount Due");
     
    t = new JTextField(20);
    t1 = new JTextField(20); 
    t2 = new JTextField(20);
    t3 = new JTextField(20);
    t4 = new JTextField(20); 
    t5 = new JTextField(20); 
    t6 = new JTextField(20);
    t7 = new JTextField(20);
    t8 = new JTextField(20); 
    t9 = new JTextField(20);
    t10 = new JTextField(20); 
    t11 = new JTextField(20);
    t12 = new JTextField(20);
     
    JPanel p = new JPanel ();
    p.add (RoomNumber);
    p.add (t);
    p.add (Firstname);
    p.add (t1);
    p.add (Lastname); 
    p.add (t2);
    p.add (MobilePhoneNumber); 
    p.add (t3);
    p.add (EmailAddress);
    p.add (t4);
    p.add (RoomType ); 
    p.add (t5); 
    p.add (NoofAdults ); 
    p.add (t6); 
    p.add (NoofChildren);
    p.add (t7); 
    p.add (CheckInDate);
    p.add (t8);
    p.add (CheckOutDate); 
    p.add (t9); 
    p.add (ModeofPayment); 
    p.add (t10); 
    p.add (AmountPaid); 
    p.add (t11); 
    p.add (AmountDue);
    p.add (t12);
    p.add (b1);
    p.add (b2);
    p.add (b3);
    p.add (b4);
    p.add (ud);
    p.add (del);
    p.add (nr);
    p.add (save);
    p.add (rep);
     
     
    f.add (p);
     
    try
    {
        rs.next();
        t.setText (rs.getString("Room Number"));
        t1.setText (rs.getString("First name")); 
        t2.setText (rs.getString("Last name"));
        t3.setText (rs.getString("Mobile Phone Number")); 
        t4.setText (rs.getString("Email Address"));
        t5.setText (rs.getString("Room Type"));
        t6.setText (rs.getString("No of Adults"));
        t7.setText (rs.getString("No of Children")); 
        t8.setText (rs.getString("Check In Date"));
        t9.setText (rs.getString("Check Out Date"));
        t10.setText (rs.getString("Mode of Payment"));
        t11.setText (rs.getString("Amount Paid"));
        t12.setText (rs.getString("Amount Due"));
     }
    catch (Exception ex)
     {
     
     }
     }
    public void btnAction ()
    {
        b1.addActionListener (new ActionListener(){
            public void actionPerformed (ActionEvent e)
            {
        try
        {
         if (rs.next ()) 
         {
        t.setText  (rs.getString("Room Number"));
        t1.setText (rs.getString("First name")); 
        t2.setText (rs.getString("Last name"));
        t3.setText (rs.getString("Mobile Phone Number")); 
        t4.setText (rs.getString("Email Address"));
        t5.setText (rs.getString("Room Type"));
        t6.setText (rs.getString("No of Adults"));
        t7.setText (rs.getString("No of Children")); 
        t8.setText (rs.getString("Check In Date"));
        t9.setText (rs.getString("Check Out Date"));
        t10.setText (rs.getString("Mode of Payment"));
        t11.setText (rs.getString("Amount Paid"));
        t12.setText (rs.getString("Amount Due")); 
         }
         else
         {
             rs.previous();
             JOptionPane.showMessageDialog(null, "No More Records");
         }
        }
        catch (Exception ex) 
       {
     
        }
     
            }
        });
        b2.addActionListener (new ActionListener(){
            public void actionPerformed (ActionEvent e)
            {
        try
        {
         if (rs.previous ()) 
         {
        t.setText  (rs.getString("Room Number"));
        t1.setText (rs.getString("First name")); 
        t2.setText (rs.getString("Last name"));
        t3.setText (rs.getString("Mobile Phone Number")); 
        t4.setText (rs.getString("Email Address"));
        t5.setText (rs.getString("Room Type"));
        t6.setText (rs.getString("No of Adults"));
        t7.setText (rs.getString("No of Children")); 
        t8.setText (rs.getString("Check In Date"));
        t9.setText (rs.getString("Check Out Date"));
        t10.setText (rs.getString("Mode of Payment"));
        t11.setText (rs.getString("Amount Paid"));
        t12.setText (rs.getString("Amount Due")); 
         }
         else
         {
             rs.next();
             JOptionPane.showMessageDialog(null, "No More Records");
         }
        }
        catch (Exception ex) 
       {
     
        }
     
            }
        });
        b3.addActionListener (new ActionListener(){
            public void actionPerformed (ActionEvent e)
            {
        try
        {
        rs.last (); 
         {
        t.setText  (rs.getString("Room Number"));
        t1.setText (rs.getString("First name")); 
        t2.setText (rs.getString("Last name"));
        t3.setText (rs.getString("Mobile Phone Number")); 
        t4.setText (rs.getString("Email Address"));
        t5.setText (rs.getString("Room Type"));
        t6.setText (rs.getString("No of Adults"));
        t7.setText (rs.getString("No of Children")); 
        t8.setText (rs.getString("Check In Date"));
        t9.setText (rs.getString("Check Out Date"));
        t10.setText (rs.getString("Mode of Payment"));
        t11.setText (rs.getString("Amount Paid"));
        t12.setText (rs.getString("Amount Due")); 
         }
     
        }
        catch (Exception ex) 
       {
     
        }
     
            }
        });
        b4.addActionListener (new ActionListener(){
            public void actionPerformed (ActionEvent e)
            {
        try
        {
         rs.first (); 
         {
        t.setText  (rs.getString("Room Number"));
        t1.setText (rs.getString("First name")); 
        t2.setText (rs.getString("Last name"));
        t3.setText (rs.getString("Mobile Phone Number")); 
        t4.setText (rs.getString("Email Address"));
        t5.setText (rs.getString("Room Type"));
        t6.setText (rs.getString("No of Adults"));
        t7.setText (rs.getString("No of Children")); 
        t8.setText (rs.getString("Check In Date"));
        t9.setText (rs.getString("Check Out Date"));
        t10.setText (rs.getString("Mode of Payment"));
        t11.setText (rs.getString("Amount Paid"));
        t12.setText (rs.getString("Amount Due")); 
         }
     
        }
        catch (Exception ex) 
       {
     
        }
     
            }
        });
        ud.addActionListener (new ActionListener(){
            public void actionPerformed (ActionEvent e)
            {
     
                String RoomNumber = t.getText();
                String Firstname = t1.getText();
                String Lastname = t2.getText(); 
                String MobilePhoneNumber = t3.getText();
                String EmailAddress = t4.getText();
                String RoomType = t5.getText();
                String NoofAdults = t6.getText(); 
                String NoofChildren = t7.getText();
                String CheckInDate = t8.getText();
                String CheckOutDate = t9.getText();
                String ModeofPayment = t10.getText();
                String AmountPaid = t11.getText(); 
                String AmountDue = t12.getText();
     
                try
                {
                  rs.updateString("Room Number" , RoomNumber);
                  rs.updateString("First Name" , Firstname);
                  rs.updateString("Last name", Lastname);
                  rs.updateString("Mobile Phone Number", MobilePhoneNumber);
                  rs.updateString("Email Address", EmailAddress);
                  rs.updateString("Room Type", RoomType);
                  rs.updateString("No of Adults", NoofAdults);
                  rs.updateString("No of Children", NoofChildren);
                  rs.updateString("Check In Date", CheckInDate);
                  rs.updateString("Check Out Date", CheckOutDate);
                  rs.updateString("Mode of Payment", ModeofPayment);
                  rs.updateString("Amount Paid", AmountPaid);
                  rs.updateString("Amount Due", AmountDue);
                  rs.updateRow ();
     
                  JOptionPane.showMessageDialog(null, "Record updated");
     
                } 
                catch (Exception Ex)
                {
     
     
     
     
    }
        }
        });
        del.addActionListener (new ActionListener(){
            public void actionPerformed (ActionEvent e)
            {
                try
                {
        rs.deleteRow();
        st.close();
        rs.close();
        st = con.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
       String sql = ("select * from Room Reservations");
        rs = st.executeQuery(sql);
        rs.next();
        t.setText  (rs.getString("Room Number"));
        t1.setText (rs.getString("First name")); 
        t2.setText (rs.getString("Last name"));
        t3.setText (rs.getString("Mobile Phone Number")); 
        t4.setText (rs.getString("Email Address"));
        t5.setText (rs.getString("Room Type"));
        t6.setText (rs.getString("No of Adults"));
        t7.setText (rs.getString("No of Children")); 
        t8.setText (rs.getString("Check In Date"));
        t9.setText (rs.getString("Check Out Date"));
        t10.setText (rs.getString("Mode of Payment"));
        t11.setText (rs.getString("Amount Paid"));
        t12.setText (rs.getString("Amount Due")); 
     
                }
                catch (Exception ex)
                {
     
                }
            }
                });
        nr.addActionListener (new ActionListener(){
            public void actionPerformed (ActionEvent e)
            {
            t.setText(" ");
            t1.setText(" "); 
            t2.setText(" ");
            t3.setText(" ");
            t4.setText(" ");
            t5.setText(" ");
            t6.setText(" ");
            t7.setText(" "); 
            t8.setText(" "); 
            t9.setText(" "); 
            t10.setText(" "); 
            t11.setText(" ");
            t12.setText(" ");
     
     
            }
     
                });
        save.addActionListener (new ActionListener(){
            public void actionPerformed (ActionEvent e)
            {
                String RoomNumber = t.getText();
                String Firstname = t1.getText();
                String Lastname = t2.getText(); 
                String MobilePhoneNumber = t3.getText();
                String EmailAddress = t4.getText();
                String RoomType = t5.getText();
                String NoofAdults = t6.getText(); 
                String NoofChildren = t7.getText();
                String CheckInDate = t8.getText();
                String CheckOutDate = t9.getText();
                String ModeofPayment = t10.getText();
                String AmountPaid = t11.getText(); 
                String AmountDue = t12.getText();
     
                 try {
                  rs.moveToInsertRow();
                  rs.updateString("Room Number" , RoomNumber);
                  rs.updateString("First Name" , Firstname);
                  rs.updateString("Last name", Lastname);
                  rs.updateString("Mobile Phone Number", MobilePhoneNumber);
                  rs.updateString("Email Address", EmailAddress);
                  rs.updateString("Room Type", RoomType);
                  rs.updateString("No of Adults", NoofAdults);
                  rs.updateString("No of Children", NoofChildren);
                  rs.updateString("Check In Date", CheckInDate);
                  rs.updateString("Check Out Date", CheckOutDate);
                  rs.updateString("Mode of Payment", ModeofPayment);
                  rs.updateString("Amount Paid", AmountPaid);
                  rs.updateString("Amount Due", AmountDue);
                  rs.insertRow();
                  st.close();
        rs.close();
        st = con.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
        String sql = ("select * from Room Reservations");
        rs = st.executeQuery(sql);
        rs.next();
        t.setText  (rs.getString("Room Number"));
        t1.setText (rs.getString("First name")); 
        t2.setText (rs.getString("Last name"));
        t3.setText (rs.getString("Mobile Phone Number")); 
        t4.setText (rs.getString("Email Address"));
        t5.setText (rs.getString("Room Type"));
        t6.setText (rs.getString("No of Adults"));
        t7.setText (rs.getString("No of Children")); 
        t8.setText (rs.getString("Check In Date"));
        t9.setText (rs.getString("Check Out Date"));
        t10.setText (rs.getString("Mode of Payment"));
        t11.setText (rs.getString("Amount Paid"));
        t12.setText (rs.getString("Amount Due")); 
     
     
     
    } 
    catch (Exception ex)
    {
     
    }
     
    }
        }); 
     
        rep.addActionListener (new ActionListener(){
            public void actionPerformed (ActionEvent e)
            {
                try{
                   String report = "C:\\Users\\Stacy\\Documents\\NetBeansProjects\\COI Room Management System\\src\\Login\\COI Room Report";
               JasperReport jr = JasperCompileManager.compileReport(report);
               JasperPrint jp = JasperFillManager.fillReport(jr, null, con);
               JasperViewer.viewReport(jp);
     
                }
                catch (Exception ex)
                {
     
                }
     
     
            }
        });
    }
    public static void main (String []args)
    {
     
    new GUI();
     }
    }

    Login code Login.java
    package Login;
     
    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
     
    public class Login {
     
        Connection con;
        Statement st;
        ResultSet rs;
     
        JFrame f = new JFrame ("COI RMS Login");
        JLabel l = new JLabel ("Username:");
        JLabel l1 = new JLabel ("Password:");
        JTextField t = new JTextField (20);
        JTextField t1 = new JTextField (20);
        JButton b = new JButton ("Login");
     
     
        public Login()
        {
            connect();
            frame();
        }
     
        public void connect()
        {
            try
        {
          String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; 
          Class.forName(driver);
          String db = "jdbc:odbc:COI RMS";
          con = DriverManager.getConnection(db);
          st = con.createStatement();
     
        }
            catch (Exception ex)
        {
     
     
        }
        }
        public void frame()
        {
            f.setSize(600, 400);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setVisible(true);
     
            JPanel p = new JPanel();
     
             p.add(l);
             p.add(t);
             p.add(l1);
             p.add(t1);
             p.add(b);
     
             f.add(p);
     
             b.addActionListener (new ActionListener(){
            public void actionPerformed (ActionEvent e)
            {
                try
                {
             String Username = t.getText().trim();
             String Password = t1.getText().trim();
             String sql = "select Username,Password from Login Details where Username = '"+Username+"'and Password = '"+Password+"'";
             rs = st.executeQuery(sql);
             int count = 0;
             while (rs.next())
             {
                count = count + 1;
     
             }
             if (count ==1)
             {
                 JOptionPane.showMessageDialog(null, "Username found, Access Granted!");
             }
             else if (count >1)
             {
                 JOptionPane.showMessageDialog(null, "Duplicate Username, Access Denied!");
             }
             else
             {
                 JOptionPane.showMessageDialog(null, "Username not found!");
     
             }
     
                }
                catch (Exception ex)
     
                    {
     
                    }
     
             }
             });
        }
        public static void main (String [] args)
        {
         new Login ();   
        }
     
    }

    Please help me out. Thanks,


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,287
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: My Java Ms Access Project is running successfully but it still has errors. Please help!

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

    I may not be serious enough to reply, but here goes:

    Give your variables better names.

    Don't leave empty catch blocks. You may be losing important info that could help you resolve your issues.

    Good luck!

Similar Threads

  1. Replies: 3
    Last Post: June 5th, 2013, 03:46 PM
  2. [SOLVED] Program is running successfully but still getting error message..
    By sumit043020701 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 24th, 2011, 12:26 AM
  3. Random Errors Occurring When Running Game in Eclipse
    By WhenThCome4Me in forum Java IDEs
    Replies: 22
    Last Post: September 1st, 2011, 07:29 AM
  4. Replies: 3
    Last Post: February 23rd, 2011, 01:27 AM
  5. Running servlet from java project
    By raj07 in forum Java Servlet
    Replies: 1
    Last Post: February 19th, 2011, 07:11 PM

Tags for this Thread