Skip to main content

Inserting data into table injsp page

1 reply [Last post]
guravharsha
Offline
Joined: 2008-07-08

Hi,
my adduser.jsp page consist of form with field username,groupid like.
I am forwarding this page to insertuser.jsp. my aim is that when I submit adduser.jsp page then the field filled in form should insert into the usertable.The insertuser.jsp is like:
String USERID=request.getParameter("id");
String NAME=request.getParameter("name");
String GROUPID=request.getParameter("group");
InitialContext context = new InitialContext();
DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/mynewdatabase");
Connection conn = ds.getConnection();
context.close();
Statement stmt=conn.createStatement();
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery("select UserId,GroupId, emailid from user");
rs.next();
rs.updateString("userId=+"id"+");
rs.updateString("GroupId=+"group"+")
rs.updateString("emailid=+"name"+");

rs.updateRow();
rs.close();

But showing error at the above bold lines as:can not find symbol:(method updatestring(java.lang.string))2.')' 3.';' expected.
Really Speaking I am newbie in this java world.
is there any other way?
Thanks and regards
haresh

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
guravharsha
Offline
Joined: 2008-07-08

Hi pelse refer the new post:
Hi,
my adduser.jsp page consist of form with field username,groupid like.
I am forwarding this page to insertuser.jsp. my aim is that when I submit adduser.jsp page then the field filled in form should insert into the usertable.The insertuser.jsp is like:
<% String USERID=request.getParameter("id");
String NAME=request.getParameter("name");
String GROUPID=request.getParameter("group");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mynewdatabase","root", "root123");
PreparedStatement st;
st = con.prepareStatement("Insert into user values (1,2,4)");
st.setString(1,USERID);
st.setString(2,GROUPID);
st.setString(4,NAME);
// PreparedStatement.executeUpdate();//
}catch(Exception ex){
System.out.println("Illegal operation");

}
%>

But showing error at the marked lines lines as:non static method executeupdate can not be referenced from static context.
Really Speaking I am newbie in this java world.
whether you have any other solution for above issue?
waiting Your valuable suggestion.
Thanks and regards
haresh