File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes updation of database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "updation of database" Watch "updation of database" New topic
Author

updation of database

shelly sharma
Ranch Hand

Joined: Sep 17, 2003
Posts: 32
I am trying to update the table emp_details. I had written a html form for
taking the input from the user, a jsp file for forwarding the request to a bean and a bean for updating a record of the emp_details table. When i test them in the server no error is coming. But the database is not updating.Here is the bean . Is the sql query written for updation is not correct.If yes then how should i write this query.
package bean;
import java.sql.*;
public class EmployeeInfoBean{
private String employeename,temporaryaddress,permanentaddress,emailaddress;
private int employeeno,departmentid,designationid,telephoneno,skillsetid;

public void setEmployeename(String input)
{
employeename=input;
}
public String getEmployeename()
{
return employeename;
}
public void setTemporaryaddress(String input)
{
temporaryaddress=input;
}
public String getTemporaryaddress()
{
return temporaryaddress;
}
public void setPermanentaddress(String input)
{
permanentaddress=input;
}
public String getPermanentaddress()
{
return permanentaddress;
}
public void setEmailaddress(String input)
{
emailaddress=input;
}
public String getEmailaddress()
{
return emailaddress;
}
public void setTelephoneno(int input)
{
telephoneno=input;
}
public int getTelephoneno()
{
return telephoneno;
}
public void setEmployeeno(int input)
{
employeeno=input;
}
public int getEmployeeno()
{
return employeeno;
}
public void setDepartmentid(int input)
{
departmentid=input;
}
public int getDepartmentid()
{
return departmentid;
}
public void setDesignationid(int input)
{
designationid=input;
}
public int getDesignationid()
{
return designationid;
}
public void setSkillsetid(int input)
{
skillsetid=input;
}
public int getSkillsetid()
{
return skillsetid;
}
public void updateDatabase(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn=
DriverManager.getConnection("jdbc dbc:employee1","","");
String sql ="UPDATE emp_details SET" + "employeename=?,temporaryaddress=?, permanentaddress=?,emailaddress=?, telephoneno=?, departmentid=?, designationid=?, skillsetid=? where employeeno=?";

PreparedStatement statement=conn.prepareStatement(sql);
statement.setInt(1, employeeno);
statement.setString(2, employeename);
statement.setString(3, temporaryaddress);
statement.setString(4, permanentaddress);
statement.setInt(5, telephoneno);
statement.setString(6, emailaddress);
statement.setInt(7, skillsetid);
statement.setInt(8, departmentid);
statement.setInt(9, designationid);


statement.executeQuery();

}
catch (Exception e){}
}
}
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
you might want to make sure you either commit the update or set autocommit to true.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Since this is more about the JDBC/SQL than JSP, I'm moving this to the JDBC forum.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
jQuery in Action, 2nd edition
 
subject: updation of database
 
Similar Threads
Struts Action not Forwarding to jsp........
Joining tables
java.sql.SQLException: Missing IN or OUT parameter at index:: 1
JSP returning old data, database was changed correctly!
Model to add to a database