Friday, 23 March 2018

Java Database with MS Access

Hi All,

Use this code

private void addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addActionPerformed
try
{
       String id1=id.getText();
String name1=name.getText();
     
        String password1=password.getText();
     
       
       
       
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection con=null;
con=DriverManager.getConnection("jdbc:odbc:bugtrack");
Statement smt1=con.createStatement();
                Statement smt2=con.createStatement();
                 Statement smt3=con.createStatement();
                smt1.executeUpdate("insert into login values('"+name1+"','tester','"+password1+"')");
                smt1.close();
smt2.executeUpdate("insert into tester values('"+id1+"','"+name1+"','"+password1+"','not assigned' )");
               //JOptionPane.showMessageDialog(null, "registred","success",JOptionPane.PLAIN_MESSAGE);
               System.out.println("registred"); 
               // setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 
               ResultSet rs=null;

//Statement smt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
               int i=0;
                 
rs=smt3.executeQuery("select * from tester");
               
                while(rs.next())
{
                    jScrollPane1.setViewportView(jTable1);
                    jTable1.setValueAt(rs.getString("id"),i,0);
                    jTable1.setValueAt(rs.getString("tname"),i,1);
                     jTable1.setValueAt(rs.getString("status"),i,2);
                   
                 
                  i++;
                }
                smt1.close();
        smt2.close();
                smt3.close();
con.close();
                //setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
//response.sendRedirect("secon.jsp");
               // this.processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
                 //closewindow();
}
catch(Exception e)
{
System.out.println("Error="+e);
}
    // TODO add your handling code here:
}

No comments:

Post a Comment

Swing Menu

Hi All, Use this code. ------------------------------------------------------- package placement; import java.awt.*; import java.io.*...