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 red lines as:can not symbol:(method updatestring(java.lang.string))2.')' 3.';' expected.
Really Speaking I am newbie in this java world.
waiting Your valuable suggestion.
Thanks and regards
haresh

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

  1. Accessing database from JSP is wrong thing to do, you should access DB only from servlet
  2. The PreparedStatement.executeUpdate(); should be st.executeUpdate();
  3. Closing connection on the end would be nice

Dear sir,
Thank you very very much for your valuable suggestion.Sir I hertly wish to thanks for your post. I am one of the java newbie working at one company client office independantly.
I am stuck at that code nearly 3-hours and your one post couses me become tension free.

Thanks a lot.
Your faithfully
Haresh


  1. Accessing database from JSP is wrong thing to do, you should access DB only from servlet
  2. The PreparedStatement.executeUpdate(); should be st.executeUpdate();
  3. Closing connection on the end would be nice
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.