TOMCAT/MYSQL/JSP

K

Kevin Robinson

Can anyone please advise me about a problem I have trying to connect to
MYSQL using TOMCAT and a jsp.

I have tomcat 4.1.24 , mysql 4.1.7 and the jdbc driver 2.0.14.
The jdbc driver is in tomcat\common\lib\org.gjt.mm.mysql.Driver.
The classpath includes c:\tomcat\common\lib.

I cannot however get the jsp to access the database.
I tried a userid and a password in the jsp but it still didn't work

Can anyone tell me what is wrong???

I have a mysql database called bfg and the following jsp:

<HTML>
<HEAD><TITLE>Employee List</TITLE></HEAD>
<BODY>
<%@ page import="java.sql.*" %>
<TABLE BORDER=1 width="75%">
<TR><TH>Last Name</TH><TH>First Name</TH></TR>
<%
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bfg");
st = conn.createStatement();
rs = st.executeQuery("select * from employees");
while(rs.next()) {
%>
<TR><TD><%= rs.getString("lname_txt") %></TD>
<TD><%= rs.getString("fname_txt") %></TD></TR>
<%
}
%>
</TABLE>
<%
} catch (java.sql.SQLException ex) {
ex.printStackTrace();
%>
</TABLE>
Ooops, something bad happened:
<%
} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();
}

%>
</BODY>
</HTML>
 
A

atishay.kumar

what error r u getting ??
also connection setting should be
DriverManager.getConnection(connectionURL, "username","password");

for ex DriverManager.getConnection("jdbc:mysql://localhost:3306/bfg",
"username","password");
 
R

Ryan Stewart

Kevin Robinson said:
Can anyone please advise me about a problem I have trying to connect to
MYSQL using TOMCAT and a jsp.

I have tomcat 4.1.24 , mysql 4.1.7 and the jdbc driver 2.0.14.
The jdbc driver is in tomcat\common\lib\org.gjt.mm.mysql.Driver.
The classpath includes c:\tomcat\common\lib.

I cannot however get the jsp to access the database.
I tried a userid and a password in the jsp but it still didn't work

Can anyone tell me what is wrong???

I have a mysql database called bfg and the following jsp:
[...]
1) Show us error messages.
2) If you only have that class in common/lib, you're missing a lot. You
should have a JAR file which should *not* be unpacked.
3) Your driver should actually be in shared/lib or your application's
WEB-INF/lib. See
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/class-loader-howto.html
 
R

Ryan Stewart

what error r u getting ??
also connection setting should be
DriverManager.getConnection(connectionURL, "username","password");

for ex DriverManager.getConnection("jdbc:mysql://localhost:3306/bfg",
"username","password");
User and password are not required, and he already said he tried them.
 
A

atishay kumar

if username n password is not needed, how will the db know which user
is trying to connect to the db and does it have access of not
 
R

Ryan Stewart

atishay kumar said:
if username n password is not needed, how will the db know which user
is trying to connect to the db and does it have access of not
You can access the database anonymously, or the username and password can be
included in the connection string.

Please quote the relevant parts of the post to which you are replying so
that we can understand what you're saying.
 
K

Kevin Robinson

The error message that I obtain fron the Tomcat command window is as
follows:

java.sql.SQLException: Communication failure during handshake. Is there a
server running on localhost:3306?
at org.gjt.mm,mysql.MysqlIO.init(Unknown Source)
at org.gjt.mm,mysql.Connection.connectionInit(Unkown Source)
at org.gjt.mm,mysql.jdbc2.Connection.connectionInit(Unkown Source)
at org.gjt.mm,mysql.Driver.connect(Unkown Source)
at java,sql.DriverManager.getConnection(DriverManager.java:512)
at java,sql.DriverManager.getConnection(DriverManager.java:193)


There is more stuff after this.
To me it looks as if it cant find the database on port 3306 but the database
is up and running as I can acces it
with mysql administrator and SQLyog on prt 3306.

The OS is XP home edition and the database server starts up automatically.


Thanks
 
A

atishay kumar

are you able to access the database using the mysql client. you will
find a exe as mysql in bin directory of your mysql installation
directory. are you able to login using that...
i recently used some other jar for conencting to the mysql db on
windows. i can send you that jar find and relevant jsp portion of the
code....
cheers
atishay
 
R

Ryan Stewart

Kevin Robinson said:
The error message that I obtain fron the Tomcat command window is as
follows:

java.sql.SQLException: Communication failure during handshake. Is there a
server running on localhost:3306?
at org.gjt.mm,mysql.MysqlIO.init(Unknown Source)
at org.gjt.mm,mysql.Connection.connectionInit(Unkown Source)
at org.gjt.mm,mysql.jdbc2.Connection.connectionInit(Unkown Source)
at org.gjt.mm,mysql.Driver.connect(Unkown Source)
at java,sql.DriverManager.getConnection(DriverManager.java:512)
at java,sql.DriverManager.getConnection(DriverManager.java:193)

There is more stuff after this.
To me it looks as if it cant find the database on port 3306 but the
database
is up and running as I can acces it
with mysql administrator and SQLyog on prt 3306.

The OS is XP home edition and the database server starts up automatically.
Try restarting your MySQL server if you haven't already. Try upgrading to
the latest driver version. Have a look at some MySQL documentation for
version 4.1 and/or later. Looking around the net, I've seen mention of MySQL
changing its password storage format and something about an
"--old-passwords" switch and OLD_PASSWORD() function.
 
K

Kevin Robinson

Thanks all for your help.

I upgraded my jdbc driver and everything now works fine.

Thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top