0 down vote favorite Hi I'm Riya a B.Tech. student and i have to make a corejava project on the topic COLLEGE MANAGEMENT SYSTEM . I have created the required database using MS Access. I m facing problem in a code which i m attaching here. Actually i want to update a data in the data base so i have made 2 frames in one of them Roll no. is asked when it is entered then the 2nd frame opens and asks Enter Marks to be updated...when i enter the marks to be updated then a dialogue box opens shoing "Marks Updated Successfully". Till here i don't have any problem..the problem is when i open the database i see that actually the Marks is not updated there.So please please please somebody help me solving this problem. **The code is as follows: !ST FRAME** import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; class MyFrame03 extends JFrame implements ActionListener { JLabel l1; JTextField t1; JPanel p1,p2; JButton b1; Connection con; PreparedStatement pst; String s1; MyFrame03() { setLayout(new GridLayout(4,1)); setTitle("Enter Data Required"); setBackground(Color.blue); l1=new JLabel("Roll no"); t1=new JTextField(12); p1=new JPanel(); p2=new JPanel(); b1=new JButton("SUBMIT"); p1.add(l1); p1.add(t1); p2.add(b1); add(p1,"Center"); add(p2,"South"); b1.addActionListener(this); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400,500); setVisible(true); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("Jdbc:Odbc:dsn3"); if(con!=null) System.out.println("Connection Established"); } catch(Exception e) { System.out.println("exception"); } } public void actionPerformed(ActionEvent e1) { if(e1.getSource()==b1) { s1=t1.getText(); try { pst=con.prepareStatement("insert into stud values(?)"); pst.setString(1,s1); pst.executeUpdate(); con.commit(); con.close(); } catch(SQLException e) { System.out.println("except1"); } MyFrame04 m1=new MyFrame04(s1); dispose(); } } public static void main(String s[]) throws SQLException { MyFrame03 m1 =new MyFrame03(); } } 2nd FRAME import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.sql.*; class MyFrame04 extends JFrame implements ActionListener { JLabel l1; JTextField t1; JPanel p1,p2; JButton b1; String s1,s2; Connection con; PreparedStatement pst; public MyFrame04(String s1) { this.s1=s1; setLayout(new GridLayout(4,1)); setTitle("Update Marks"); setBackground(Color.blue); l1=new JLabel("Enter Marks"); t1=new JTextField(12); b1=new JButton("SUBMIT"); p1=new JPanel(); p2=new JPanel(); p1.add(l1); p1.add(t1); p2.add(b1); add(p1,"Center"); add(p2,"South"); b1.addActionListener(this); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400,500); setVisible(true); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("Jdbc:Odbc:dsn3"); if(con!=null) System.out.println("Connection Established"); } catch(Exception e) { System.out.println("exception"); } } public void actionPerformed(ActionEvent e1) { if(e1.getSource()==b1) { s2=t1.getText(); try { pst=con.prepareStatement("UPDATE stud set Marks=? WHERE Roll no=?"); pst.setString(1,s2); pst.setString(2,s1); pst.executeUpdate(); con.commit(); con.close(); } catch(SQLException e) { System.out.println("except1"); } JOptionPane.showMessageDialog(this ,"Marks updated succesfully"); dispose(); } } } Thankyou
see in console if any exception is occuring or not write this line JOptionPane.showMessageDialog(this ,"Marks updated succesfully"); inside try block and check if it displaying it. and change below code catch(SQLException e) { System.out.println("except1"); } to catch(SQLException e) { System.out.println("except1: "+e); } to check what kind of exception has occured