User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 402,807 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,054 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 1052 | Replies: 4 | Solved
Reply
Join Date: Jun 2008
Posts: 35
Reputation: guravharsha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
guravharsha guravharsha is offline Offline
Light Poster

Inserting data into table in jsp page

  #1  
Jul 9th, 2008
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 symbolmethod updatestring(java.lang.string))2.')' 3.';' expected.
Really Speaking I am newbie in this java world.
waiting Your valuable suggestion.
Thanks and regards
haresh
Last edited by peter_budo : Jul 9th, 2008 at 4:45 am. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2008
Posts: 35
Reputation: guravharsha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
guravharsha guravharsha is offline Offline
Light Poster

Re: Inserting data into table in jsp page

  #2  
Jul 9th, 2008
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
Last edited by peter_budo : Jul 9th, 2008 at 7:21 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,239
Reputation: peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough 
Rep Power: 10
Solved Threads: 270
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Inserting data into table in jsp page

  #3  
Jul 9th, 2008
  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
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Jun 2008
Posts: 35
Reputation: guravharsha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
guravharsha guravharsha is offline Offline
Light Poster

Re: Inserting data into table in jsp page

  #4  
Jul 9th, 2008
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







Originally Posted by peter_budo View Post
  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
Reply With Quote  
Join Date: Jan 2008
Posts: 12
Reputation: senthil_sivanat is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
senthil_sivanat senthil_sivanat is offline Offline
Newbie Poster

Re: Inserting data into table in jsp page

  #5  
Jul 23rd, 2008
If the problem is solved, please close the thread. Else see this
http://jspcodes.elementfx.com/codesn...d=3&category=1
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 10:56 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC