Increment value of MySQL columnJSP button

Reply

Join Date: Oct 2009
Posts: 5
Reputation: romilc is an unknown quantity at this point 
Solved Threads: 0
romilc romilc is offline Offline
Newbie Poster

Increment value of MySQL columnJSP button

 
0
  #1
Nov 9th, 2009
the following is the code:

  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
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 463 | Replies: 0
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC