
Hey friends I am a beginner to java,and my problem is related to updation query in ms-access.Actually have created a database and through a jform button I am retrieving data in text fields and then updation is made in these textboxes and then updation query is fired through a button .Now problem is at text fields are getting data from database but updation is not executed and exception is given that 'top few parameters in update query,but I have checked all parameters correctly.And I can't find solution of this problem.please help me.

Here is a code that updates the data. When the user enter any id and click the edit button, the record of that corresponding id, values will get displayed into the form. Then you can easily update that particular record.
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
class UpdateInformation{
JFrame f;
JPanel p2;
JLabel l7,l8,l9,l10;
JTextField tf7,tf8,tf9,tf10;
JButton editbtn1,editbtn2 ;
UpdateInformation(){
f=new JFrame("Form");
p2=new JPanel(new GridLayout(5,2));
l7=new JLabel("Employee ID:");
l8=new JLabel("Employee Name:");
l9=new JLabel("Employee Address:");
l10=new JLabel("Salary:");
tf7=new JTextField(12);
tf8=new JTextField(12);
tf9=new JTextField(12);
tf10=new JTextField(12);
editbtn1=new JButton("Edit ");
editbtn2=new JButton("Save");
p2.add(l7);
p2.add(tf7);
p2.add(l8);
p2.add(tf8);
p2.add(l9);
p2.add(tf9);
p2.add(l10);
p2.add(tf10);
p2.add(editbtn1);
p2.add(editbtn2);
editbtn1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String value=tf7.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:student");
PreparedStatement st=con.prepareStatement("select * from employee where id=?");
st.setString(1,value);
ResultSet res=st.executeQuery();
res.next();
tf7.setText(res.getString("id"));
tf8.setText(res.getString("name"));
tf9.setText(res.getString("address"));
tf10.setText(res.getString("salary")));
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(p2,"Can not edit data");
}
}
});
editbtn2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
try
{
int x=JOptionPane.showConfirmDialog(p2,"Confirm edit? All data will be replaced");
if(x==0){
try{
String value1=tf7.getText();
String value2=tf8.getText();
String value3=tf9.getText();
String value4=tf10.getText();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:student");
Statement st=con.createStatement();
st.executeUpdate("update employee set name='"+value2+"', address='"+value3+"', salary='"+value4+"' where id='"+value1+"' ");
JOptionPane.showMessageDialog(p2,"Updated successfully");
con.close();
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(p2,"Error in updating edit fields");
}
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(p2,"Error");
}
}
});
}
void dis()
{
f.getContentPane().add(p2);
f.setTitle("Update Records");
f.setSize(350,180);
f.setVisible(true);
f.setResizable(true);
}
public static void main(String z[]){
UpdateInformation pro=new UpdateInformation();
pro.dis();
}
}