943,937 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 1008
  • JSP RSS
Nov 9th, 2009
0

Increment value of MySQL columnJSP button

Expand Post »
the following is the code:

JSP Syntax (Toggle Plain Text)
  1. <%@ page import="java.util.*" import="java.sql.*" import="java.io.*" language="java" contentType="text/html; charset=ISO-8859-1"
  2. pageEncoding="ISO-8859-1"%>
  3.  
  4. <%
  5. Integer hit = 0;
  6. Connection con = null;
  7. Statement stmt=null;
  8. ResultSet rs = null;
  9. %>
  10.  
  11. <%
  12. try
  13. {
  14. out.println();
  15. Class.forName("com.mysql.jdbc.Driver").newInstance();
  16.  
  17. con = DriverManager.getConnection("jdbc:mysql://localhost/lab2","root","root");
  18.  
  19. stmt=con.createStatement();
  20. rs=stmt.executeQuery("SELECT hitCount from table1");
  21. hit = rs.getInt("hitCount");
  22. hit = hit + 1;
  23. rs=stmt.executeQuery("UPDATE table1 set hitCount=10");
  24. rs.close();
  25. stmt.close();
  26. con.close();
  27.  
  28. }
  29. catch(Exception ex)
  30. {
  31. out.println(ex);
  32. }
  33.  
  34. %>
  35.  
  36.  
  37.  
  38. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  39.  
  40.  
  41. <html>
  42. <head>
  43. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  44. <title>Welcome!!</title>
  45. <script language="javascript">
  46. var hitCount=0;
  47. var jsvar="Hello World";
  48. function counter()
  49. {
  50. hitCount = hitCount + 1;
  51. alert(hitCount);
  52.  
  53. }
  54.  
  55.  
  56. </script>
  57. </head>
  58. <body>
  59. <FORM name="welcome" method="post">
  60. <marquee> Welcome to the Tic-Tac-Toe game!!!!</marquee>
  61. <table width="100%" border=0 cellspacing=0 cellpadding=0 align=center>
  62. <tr>
  63. <td><br></br></td>
  64. </tr>
  65. <tr>
  66. <td>
  67. <div align="center">
  68. <img src="images/tictacimg.jpg" name="1.jpg"></img>
  69. <br></br>
  70. <font color="#19A1CB" size="2" face="Verdana, Arial, Helvetica, sans-serif">
  71. <span><b>Tic Tac Toe Game</b></span><br></br>
  72. <span>Click below to start the game</span><br></br>
  73. <br></br>
  74. </font>
  75. </div>
  76. </td>
  77. </tr>
  78. <tr>
  79. <td>
  80. <div align="center">
  81. <input type="button" name="start" value="START GAME" onClick="counter()"></input>
  82. </div>
  83. </td>
  84. </tr>
  85. <tr><td><div id='counter' style="display:"><%= hit %></div></td></tr>
  86.  
  87. </table>
  88. </FORM>
  89. </body>
  90. </html>

With the above I m not able to increment the value of hitCount in the MySQL each time when the button is clicked..
tell me wats wrong with my code
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
romilc is offline Offline
5 posts
since Oct 2009

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.
Message:
Previous Thread in JSP Forum Timeline: Table locked and session was invalidated
Next Thread in JSP Forum Timeline: Query on Dropdown list





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


Follow us on Twitter


© 2011 DaniWeb® LLC