Hi i produce sample application with access 2007 and i haven't done validation that part is for u.
I'm using netbeans 6.5.1 ide and access 2007 and jcalender 1.3.3 version
and odbc data sources .
1 .first create a table in access2007 with following fields
stu_prn | stu_name | stu_date_admit | stu_fees | stu_pay_mode | stu_course | stu_education | stu_admit_type
2 .set the primary key as stu_prn.
3.Then go to the StartMenu->control panel -> Administrative tools ->
Data sources and double click DataSources .
4. Then Slect systemdsn -> click add button -> from the wizard select
Microsoft Access Driver (*.mdb,*.accdb) then click finish.
Odbc Access setup dialog appers , give student for datasource field and from
Data base section (below) click on select button select the your database
from the file browser diaog and click ok . Again click ok.
Here Is the dbclass code.
----------------------------------------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pk;
import java.sql.*;
/**
*
* @author samith
*/
public class AccessConnection {
static String uri = "jdbc:odbc:student";
private Connection getAccessConnection() {
Connection con = null;
try {
con = DriverManager.getConnection(uri, "", "");
return con;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public int insertAdmissinData(String prn, String name, String date, double fees, String pmode, String course, String edu, String admitty) throws SQLException {
Connection con = null;
Statement st = null;
String sql = "insert into Admission values ('" + prn + "','" + name + "','" + date + "'," + fees + ",'" + pmode + "','" + course + "','" + edu + "','" + admitty + "')";
try {
con = getAccessConnection();
st = con.createStatement();
int result = st.executeUpdate(sql);
return 0;
} catch (Exception e) {
e.printStackTrace();
return -1;
} finally {
if (con != null) {
con.close();
}
if (st != null) {
st.close();
}
}
}
}
---------------------------------
Here is code for jframe
--------------------------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* AdmissionFrm.java
*
* Created on Feb 26, 2010, 8:39:08 AM
*/
package pk;
import javax.swing.JOptionPane;
/**
*
* @author samith
*/
public class AdmissionFrm extends javax.swing.JFrame {
/** Creates new form AdmissionFrm */
public AdmissionFrm() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txtPrn = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
txtName = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
txtFees = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
dateAdmitdate = new org.gui.JCalendarCombo();
jLabel6 = new javax.swing.JLabel();
cmbPaymentMode = new javax.swing.JComboBox();
jLabel7 = new javax.swing.JLabel();
txtEducation = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
txtCourse = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
txtAdmissionType = new javax.swing.JTextField();
btnSave = new javax.swing.JButton();
btnClear = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("Student Admission Application");
jLabel2.setText(" Prn:");
jLabel3.setText("Name:");
jLabel4.setText("Fees :");
jLabel5.setText("Date :");
jLabel6.setText("Payment Mode:");
cmbPaymentMode.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Cheque", "Cash" }));
jLabel7.setText("Educataion:");
jLabel8.setText("Course :");
jLabel9.setText("Admission Type:");
btnSave.setText("Save");
btnSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSaveActionPerformed(evt);
}
});
btnClear.setText("Reset");
btnClear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnClearActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel3)
.addComponent(jLabel2)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addComponent(jLabel7)
.addComponent(jLabel8))
.addComponent(jLabel9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txtAdmissionType, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
.addComponent(txtPrn, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
.addComponent(txtName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
.addComponent(txtFees, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
.addComponent(dateAdmitdate, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
.addComponent(cmbPaymentMode, javax.swing.GroupLayout.Alignment.LEADING, 0, 179, Short.MAX_VALUE)
.addComponent(txtEducation, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
.addComponent(txtCourse, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(btnSave)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnClear)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGap(89, 89, 89))
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(66, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtPrn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(txtFees, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(dateAdmitdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(cmbPaymentMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(txtEducation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(txtCourse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(txtAdmissionType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnClear)
.addComponent(btnSave))
.addGap(20, 20, 20))
);
pack();
}// </editor-fold>
private void clear(){
txtAdmissionType.setText("");
txtCourse.setText("");
txtEducation.setText("");
txtFees.setText("");
txtName.setText("");
txtPrn.setText("");
}
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
try {
String prn = txtPrn.getText();
String name = txtName.getText();
String date = dateAdmitdate.getSelectedDate();
double fees = Double.parseDouble(txtFees.getText());
String pmode = cmbPaymentMode.getSelectedItem().toString();
String course = txtCourse.getText();
String edu = txtEducation.getText();
String admitty = txtAdmissionType.getText();
AccessConnection ac=new AccessConnection();
int result =ac.insertAdmissinData(prn, name, date, fees, pmode, course, edu, admitty);
clear();
if(result==0){
JOptionPane.showMessageDialog(null, "Succesfully Saved.","Information",JOptionPane.INFORMATION_MESSAGE);
}else{
JOptionPane.showMessageDialog(null, "Errors Occured.","Error",JOptionPane.ERROR_MESSAGE);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
clear();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new AdmissionFrm().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnClear;
private javax.swing.JButton btnSave;
private javax.swing.JComboBox cmbPaymentMode;
private org.gui.JCalendarCombo dateAdmitdate;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JTextField txtAdmissionType;
private javax.swing.JTextField txtCourse;
private javax.swing.JTextField txtEducation;
private javax.swing.JTextField txtFees;
private javax.swing.JTextField txtName;
private javax.swing.JTextField txtPrn;
// End of variables declaration
}
-----------------------------------
download jcalender 1.3.3 jar from
http://www.toedter.com/en/jcalendar/index.htmlwhen you create project in netbeans add those jars to your project.
Best Regards.