Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JSP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
JSP
database login update problem
muntago Richard
Ranch Hand
Posts: 82
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
good day everybody, i want to used this code for users login but each time i want the count column to update, it will return an empty page. I know may be i did not structure
this code properly especially
String query1="UPDATE vata SET count = count + 1 WHERE username='"+username+"'"; int i = stmt.executeUpdate(query1);
below is the main code
<%@ page import="java.sql.*" %> <%@ page import="java.io.*" %> <html> <head> <title>login</title> </head> <body> <% response.setContentType("text/html"); PrintWriter pw = response.getWriter(); String username = request.getParameter("username"); String password = request.getParameter("password"); int count=0; try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con=null; ResultSet rst=null; Statement stmt=null; con=DriverManager.getConnection("jdbc:mysql://localhost:3306/vat", "root", "root"); stmt=con.createStatement(); String query = "select count from vat where username='"+username+"' and password='"+password+"'"; System.out.println(query); ResultSet rs = stmt.executeQuery(query); while(rs.next()){ //count=rs.getInt(1); } if(count > 1){ pw.println("<font color=green size=5>you cannot login again</font>"); } else{ String query1="UPDATE vata SET count = count + 1 WHERE username='"+username+"'"; int i = stmt.executeUpdate(query1); pw.println("<font color=red size=5>welcome friend</font>"); } } catch(Exception e){ System.out.println(e.getMessage()); } %> thank u
Bear Bibeault
Sheriff
Posts: 67746
173
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Step 1: move the
Java
code out of a
JSP
and into a
servlet
or bean. There should be no Java code in a modern JSP.
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
HTTP status 500
login
java .lang .Number Format Error
i need help
login problem in jsp
More...