0

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

3
Contributors
4
Replies
6
Views
9 Years
Discussion Span
Last Post by senthil_sivanat
0

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

0
  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
0

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
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.