944,188 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 14521
  • JSP RSS
Oct 26th, 2007
0

how to update database using mysql and jsp

Expand Post »
can somebody prove me the coding to update the database (mysql) with JSP
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nikhita is offline Offline
15 posts
since Oct 2007
Oct 29th, 2007
0

Re: how to update database using mysql and jsp

Google is your friend! There are many examples over the internet, for example this site http://www.java2s.com/Tutorial/Java/...__Database.htm
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 875
Code tags enforcer
peter_budo is online now Online
6,659 posts
since Dec 2004
Nov 2nd, 2007
0

Re: how to update database using mysql and jsp

U can write all code using scriptlet. Simply start scriptlet,create connection, write and execute update query, close connection and scriptlet.
For Ex
<%
create connection
Create query
resultset
execute query
close connection
%>
Hope it provides u some help!!

U can find example code in google.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Shubhra is offline Offline
7 posts
since Nov 2007
Nov 2nd, 2007
0

Re: how to update database using mysql and jsp

Click to Expand / Collapse  Quote originally posted by Shubhra ...
U can write all code using scriptlet. Simply start scriptlet,create connection, write and execute update query, close connection and scriptlet.
For Ex
<%
create connection
Create query
resultset
execute query
close connection
%>
Hope it provides u some help!!

U can find example code in google.
Which is, of course, exactly the wrong way to do it, reagardless of whether it works or not.

You can also scratch your back with a butcher knife, but I wouldn't suggest it.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Nov 2nd, 2007
0

Re: how to update database using mysql and jsp

Ya OK.
What I provided was actually the short cut.
Correct way is to do all such stuff in class. Create object in jsp and simply execute the method!!

Am I correct now??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Shubhra is offline Offline
7 posts
since Nov 2007
Nov 2nd, 2007
0

Re: how to update database using mysql and jsp

Well, if you knew the right way, why did you suggest the wrong way?

As I said:

You can also scratch your back with a butcher knife, but I wouldn't suggest it.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Nov 2nd, 2007
0

Re: how to update database using mysql and jsp

Actually I wrote what came first to my mind.
Your comment stroke me to give a2nd thought.
I apologise.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Shubhra is offline Offline
7 posts
since Nov 2007
Nov 7th, 2007
0

how make a jsp page printer friendly

the link you provided was helpful. thanks a lot.

sorry for the delay in reply..

One more help needed....

can u tel me how make a jsp page printer friendly
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nikhita is offline Offline
15 posts
since Oct 2007
Mar 21st, 2010
0

use this may help u

Click to Expand / Collapse  Quote originally posted by nikhita ...
can somebody prove me the coding to update the database (mysql) with JSP
-----------------------html.jsp---------------------------

JSP Syntax (Toggle Plain Text)
  1. <%@ page contentType="text/html; charset=iso-8859-1" language="java" %>
  2. <html>
  3. <body>
  4. <form name="frm" method="post" action="om.jsp">
  5. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  6. <tr>
  7. <td width="22%">&nbsp;</td>
  8. <td width="78%">&nbsp;</td>
  9. </tr>
  10. <tr>
  11. <td>Name Student </td>
  12. <td> to<input type="text" name="studentName"></td>
  13. <td>from<input type="text" name="studentName1"></td>
  14. </tr>
  15. <tr>
  16. <td>&nbsp;</td>
  17. <td><input type="submit" name="submit" value="Submit"></td>
  18. </tr>
  19. <tr>
  20. <td>&nbsp;</td>
  21. <td>&nbsp;</td>
  22. </tr>
  23. </table>
  24. </form>
  25. </body>
  26. </html>


-----------------------------om.jsp-----------------------

JSP Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>result:</title>
  4.  
  5.  
  6. <%@ page import="java.io.*"%>
  7. <%@ page import="java.io.File"%>
  8. <%@ page import="java.util.*"%>
  9. <%@ page import="java.sql.*"%>
  10. <%@ page import="java.sql.Blob"%>
  11. <%@ page import="java.sql.PreparedStatement"%>
  12. <%@ page import="java.sql.BatchUpdateException"%>
  13. <%@ page import="javax.servlet.*"%>
  14. <%@ page import="javax.servlet.http.*"%>
  15.  
  16. <%
  17.  
  18. try
  19. {
  20.  
  21. boolean autho;
  22.  
  23. //String driver = "org.gjt.mm.mysql.Driver";
  24. Class.forName("com.mysql.jdbc.Driver").newInstance();
  25. Connection con=null;
  26. ResultSet rs=null;
  27. Statement stmt=null;
  28.  
  29.  
  30. String url="jdbc:mysql://localhost:3306/om?user=root&password=omshakthi";
  31.  
  32. out.println("no1");
  33. con=DriverManager.getConnection(url);
  34.  
  35. stmt=con.createStatement(rs.TYPE_SCROLL_SENSITIVE,rs.CONCUR_UPDATABLE);
  36.  
  37.  
  38. String name=request.getParameter("studentName");
  39.  
  40. String name1=request.getParameter("studentName1");
  41.  
  42. //stmt.executeUpdate("insert into om1(name) values('"+name+"')"); //insert
  43.  
  44.  
  45. //stmt.executeUpdate("update om1 set name='"+name+"' WHERE name='ykuy'");//update
  46.  
  47.  
  48. //name: is where u enter as get parameter
  49. //ykuy: is some store value in mysql
  50.  
  51.  
  52. //rs = stmt.executeQuery("SELECT * FROM om1"); // select all
  53.  
  54. rs = stmt.executeQuery("SELECT * FROM om1 WHERE name='"+name+"'");//use of where
  55.  
  56.  
  57. if(!rs.next())
  58. {
  59. autho=false;
  60. //out.println("not autorized");
  61. }
  62. else
  63. {
  64. autho=true;
  65. //out.println("autorized");
  66. }
  67.  
  68.  
  69. rs = stmt.executeQuery("SELECT * FROM om1 WHERE name='"+name1+"'");
  70.  
  71.  
  72. if(!rs.next())
  73. {
  74. out.println("not autorized");
  75. }
  76. else if(autho==false)
  77. {
  78. out.println("not autorized");
  79. }
  80. else
  81. {
  82. out.println("autorized");
  83. out.println("<h1>new mail from "+name1+" to "+name+"</h1>");
  84. }
  85.  
  86.  
  87.  
  88. /*
  89.  
  90. while (rs.next())
  91. {
  92. out.println("no2");
  93. out.println(rs.getString("name")+"<br>");
  94. }*/
  95.  
  96.  
  97. rs.close();
  98. }
  99.  
  100.  
  101. catch (Exception e)
  102. {
  103. out.println("no3");
  104. //out.println("<center><font size=5> Error in inserting the data</font></center>");
  105. out.println("the error is:"+e.toString());
  106. }
  107.  
  108.  
  109. %>
  110. </body>
  111. </html>
Last edited by peter_budo; Mar 21st, 2010 at 11:16 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jagadesh_pesit is offline Offline
2 posts
since Mar 2010
Mar 21st, 2010
0
Re: how to update database using mysql and jsp
@jagadesh_pesit
  1. You are just some 3 years to late with your reply
  2. You used no code tags
  3. You show database connectivity from JSP that is frown upon (bad practice)
  4. I can go on, but I rather close this thread as unproductive and sample of bad practises. You want to learn better? Then check 2 posts on the top of JSP section for more info...
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 875
Code tags enforcer
peter_budo is online now Online
6,659 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in JSP Forum Timeline: how to connect derby database to jsp
Next Thread in JSP Forum Timeline: javamail





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC