Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
|
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 10th, 2006, 01:36 AM
Registered User
 
Join Date: Jul 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default jdbc:sql:tomcat connectivity

Hi everybody,
pls help me in resolving this.
first i downloaded n installed the mysql-connector-java-3.1.13.zip ,sql server 5.0 and tomcat 5.0.28.Then to connect them i copyied the mysql-connector-java-3.1.13-bin.jar into two place
1: in the (C:\TOMCAT\Tomcat 5.0\common\lib) and
2:in the (C:\j2sdk_nb\j2sdk1.4.2\jre\lib\ext)
now let me also tell you that my tomcat installation is proper as i checked it for the file in root directory of tomcat(index.jsp)..it also works for other jsp files of mine which doesnt include MySQL connection.
Just to check the MySQL connection with jsp in tomcat i tried out one simple code where
1:I created a database named register in mysql server 5.0(using mysql command-line-client) in which i created a table named users(name,password,message)
2.now in my first jsp file that is db-login.jsp(the user has to enter a username and password) through a html form...which then is forwarded to the next page that is db-result.jsp where it will compare the name and password both from the users table in it matches then it will display the correspondin welcome message else it will ask to loginagain ..that is back to db-login jsp
IS IT RIGHT TO SAVE OUR JSP FILES /FOLDERS DIRECTLY INTO THE ROOT DIRECTORY OF TOMCAT
Attached with this, is my code and the error that i get from that.
plss resolve my problem with the db-result.jsp
thanx in advance.


,-- my jsp codes--
//code for db-login.jsp//
<%@ page language="java" contentType="text/html" errorPage="errorpage.jsp" %>
<html>
<head>
<title>login</title>
</head>
<body>
<%if(session.getAttribute("welcome")!=null)
{%>
<h3><%=session.getAttribute("welcome")%></h3>
<%}
else
{%>
please log in below to continue...
<form method="post"
action="<%=response.encodeURL("db-result.jsp")%>">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="log in"></td>
</tr>
</table>
</form>
<%}%>
</body>
</html>

///code for db-result.jsp//
<%@page language="java" contentType="text/html"
 import="java.sql.*"%>
<html>
<head><title>login</title></head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/register?user=shraddha&password=04shetty");
Statement Stmt=conn.createStatement();
ResultSet RS=Stmt.executeQuery("SELECT message FROM users WHERE name='" + request.getParameter("name") + "' AND password=PASSWORD('" +request.getParameter("password")+"')");
String message =null;
while(RS.next())
{
message=RS.getString(1);
}
RS.close();
Stmt.close();
conn.close();
%>
<%if (message!=null){
session.setAttribute("welcome",message);%>
<h3>your login has succeeded.thank you.</h3>
<%}
else{%>
<h3>your login has failed ,please try again.</h3>
<%}%>
<a href="<%=response.encodeURL("db-login.jsp") %>">
continue...</a>
</body>
</html>

/--database that i created using mysql--/
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.22-community-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| footydb |
| mysql |
| register |
| test |
+--------------------+
5 rows in set (0.38 sec)

mysql> use register;
Database changed
mysql> show tables;
+--------------------+
| Tables_in_register |
+--------------------+
| users |
+--------------------+
1 row in set (0.00 sec)

mysql> select * from users;
+-------+-------------------------------------------+-------------------+
| name | password | message |
+-------+-------------------------------------------+-------------------+
| guest | *11DB58B0DD02E290377535868405F11E4CBEFF58 | welcome stranger! |
| mike | *97EA1C051452E335A13C26602BC66194EDC17677 | hi mike! |
| linda | *1B72E7E7ECBD70C9C8881BD0F9ECA0D76D2FB26B | greetings linda! |
+-------+-------------------------------------------+-------------------+
3 rows in set (0.45 sec)

mysql>

----error that i encounter while executin db-result.jsp------
javax.servlet.ServletException: Access denied for user 'shraddha'@'localhost' (using password: YES)
    org.apache.jasper.runtime.PageContextImpl.doHandle PageException(PageContextImpl.java:825)
    org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:758)
    org.apache.jsp.db_002dresult_jsp._jspService(db_00 2dresult_jsp.java:85)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)

root cause

java.sql.SQLException: Access denied for user 'shraddha'@'localhost' (using password: YES)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:2975)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:798)
    com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java: 3700)
    com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:12 03)
    com.mysql.jdbc.Connection.createNewIO(Connection.j ava:2568)
    com.mysql.jdbc.Connection.<init>(Connection.java:1 485)
    com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:266)
    java.sql.DriverManager.getConnection(DriverManager .java:512)
    java.sql.DriverManager.getConnection(DriverManager .java:193)
    org.apache.jsp.db_002dresult_jsp._jspService(db_00 2dresult_jsp.java:49)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)

please everyone i know this is just my beginning in jsp.but i will b very thankfull to u all if u step in to help in resolvin this problem.



 
Old July 12th, 2006, 02:23 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This seems like a simple MySQL user authentication problem. Are you sure you're using the right username and password when using JDBC? For information on changing your password, or creating new MySQL user accounts, use the GRANT query: http://dev.mysql.com/doc/refman/5.0/en/grant.html

As for saving your JSPs in the root folder of Tomcat, I believe you are confused. I know your implementation is working because the stack traces show the execution thread going through your JSP -- so they're working fine. Therefore you must have placed your JSPs in /webapps/???.war/.

This is fine, but from an architectural perspective you probably want to do your development outside of the Tomcat folder and use an Ant script to build your code into a WAR and deploy it on your server. This way you can check in your project to CVS, Perforce, or some other code management system and not worry about it becoming corrupted/altered in the course of execution.

Jon Emerson
http://www.jonemerson.net/
 
Old July 15th, 2006, 11:12 AM
Registered User
 
Join Date: Jul 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you so much

 
Old July 15th, 2006, 11:15 AM
Registered User
 
Join Date: Jul 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by panacea
 This seems like a simple MySQL user authentication problem. Are you sure you're using the right username and password when using JDBC? For information on changing your password, or creating new MySQL user accounts, use the GRANT query: http://dev.mysql.com/doc/refman/5.0/en/grant.html

As for saving your JSPs in the root folder of Tomcat, I believe you are confused. I know your implementation is working because the stack traces show the execution thread going through your JSP -- so they're working fine. Therefore you must have placed your JSPs in /webapps/???.war/.

HEY THANK YOU SO MUCH,
IT WAS REALLY TO DO WITH USERNAME N PASSWORD PROBLEM...N NOW IT IS WORKIN PROPERLY..

This is fine, but from an architectural perspective you probably want to do your development outside of the Tomcat folder and use an Ant script to build your code into a WAR and deploy it on your server. This way you can check in your project to CVS, Perforce, or some other code management system and not worry about it becoming corrupted/altered in the course of execution.

Jon Emerson
http://www.jonemerson.net/





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 2005 connectivity anita SQL Server 2005 3 September 20th, 2006 10:17 AM
connectivity of c++ to sql server 2000 nigam.samir C++ Programming 0 August 12th, 2006 08:01 AM
jdbc:mysql connectivity kvenk111 Pro JSP 2 April 21st, 2006 02:25 AM
JBuilder/Tomcat/JNDI/JDBC DataSource cac07 BOOK: Professional Apache Tomcat 0 January 26th, 2006 12:28 PM
SQl Server Connectivity a_saravgi VB.NET 2002/2003 Basics 2 January 6th, 2005 12:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.