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 361,548 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 2,063 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: 500 | Replies: 4
Reply
Join Date: Mar 2008
Posts: 9
Reputation: nireekshan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nireekshan nireekshan is offline Offline
Newbie Poster

mysql+jsp

  #1  
Apr 4th, 2008
hai
i am nireekshan
i am using mySql database in this i am create employe table
Now i am davalep One .HTML Page in this i am write the employe table fieldes-----------And write Jsp page inThis i write MYSQL CONNection code And Insert Prapared Staments
Now i am run TOMCat 5.0 Server,open .HTML page INSERT EMploye Fied Values Submet ok
next Work is Down NOT store data in database
plse see my program tell me any ERROR plse ...............
HTML..............>jsp.................;

  1. <%@ page import="javax.servlet.*" %>
  2. <%@ page import="javax.servlet.http.*" %>
  3. <%@ page import="java.io.*" %>
  4.  
  5. <%@ page import="java.sql.*" %>
  6. <%
  7.  
  8. String vemp_code=request.getParameter("emp_code");
  9. String vemp_name=request.getParameter("emp_name");
  10.  
  11. Connection conn = null;
  12. ResultSet rs=null;
  13. String url = "jdbc:mysql://localhost:3306/";
  14. String driverName = "com.mysql.jdbc.Driver";
  15. String userName = "roor";
  16. String password = "root";
  17. try{
  18. Class.forName(driverName).newInstance();
  19. conn = DriverManager.getConnection("jdbc:mysql://localhost/niree",userName,password);
  20. Statement stmt = conn.createStatement();
  21. stmt.executeUpdate("use newuser;");
  22. out.println(" connection is established");
  23.  
  24. //Statement stmt = conn.createStatement();
  25. //int val = //stmt.executeUpdate("INSERT employe VALUES(?,?)");
  26. PreparedStatement pst;
  27. pst=conn.prepareStatement(" insert into employe values(?,?)");
  28. pst.setString(1,vemp_code);
  29. pst.setString(2,vemp_name);
  30. }
  31. catch(Exception e){
  32. System.out.println("error occured");
  33. e.printStackTrace();
  34. }
  35.  
  36.  
  37.  
  38. %>
Last edited by peter_budo : Apr 4th, 2008 at 2:12 pm. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,689
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 312
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: mysql+jsp

  #2  
Apr 7th, 2008
Don't write database connectivity code in a JSP; that's not what JSP's were meant for. Push all that database logic inside a servlet. Use JSP only as a presentation technology.

And BTW, have you hosted your files on the Tomcat server? What is the URL you are using to access your HTML? What kind of error do you get? Aren't the error logs useful?
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Dec 2004
Location: UAE
Posts: 398
Reputation: Sulley's Boo will become famous soon enough Sulley's Boo will become famous soon enough 
Rep Power: 5
Solved Threads: 9
Sulley's Boo's Avatar
Sulley's Boo Sulley's Boo is offline Offline
Posting Whiz

Re: mysql+jsp

  #3  
Apr 8th, 2008
and, this line is missing
pst.executeUpdate();
right ppl?

*hides*
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,576
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 184
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: mysql+jsp

  #4  
Apr 8th, 2008
I wouldn't know. As soon as I see a tag starting a scriptlet I quit reading and give the canned answer to not use Java code in JSP.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Join Date: Oct 2007
Posts: 14
Reputation: mr4top is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
mr4top's Avatar
mr4top mr4top is offline Offline
Newbie Poster

Re: mysql+jsp

  #5  
Apr 8th, 2008
#
String userName = "roor";
#
String password = "root";

i think you should take care of Name
check it plase it should be ROOT not ROOR
Mahmoud Rizk
002-010 4411 540
Admin@ErpEgypt.com
Sales and Marketing Certified.
Reply With Quote  
Reply

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

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

 

DaniWeb JSP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

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