File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "" Watch "" New topic

bernd pier
Ranch Hand

Joined: Jun 21, 2002
Posts: 30
hey andrew,
at first, if you want to connect to a database from a servlet you need a is a driver for mysql database, you can download it from (if you want to see all mysql drivers, go to the mysql page).
when you unpack the driver is a directory and the place the files lies.
i have installed this driver too, i`m using tomcat 4.0 j2sdk1.4.0 and mysql3.23.49 on a linux suse 7.3 machine,and i found it a little bit difficulte to do it, especially the installation of the mm.mysql driver in the right place.
there is a documentation on hope it will help you.
if there are problems feel free to ask, somebody will help you, maybe i?
Andrew Parker
Ranch Hand

Joined: Nov 12, 2001
Posts: 178
I put mm.mysql under /var/tomcat4/lib.
I have a test file which has the same setting on win2k and the following program runs fine, i.e. jsp can connect to mysql under win2k. However, when I used the same file and database, it did not work under linux box. Why and how should I fix it?
Here is the program:
<head><title>Employee List</title></head>
<%@ page import="java.sql.*" %>
<table border=1 width="70%">
<tr><th>Last name</th><th>First name</th></tr>
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
st = conn.createStatement();
rs = st.executeQuery("select * from employees");
while( {
<tr><td><%= rs.getString("lname_txt") %></td>
<td><%= rs.getString("fname_txt") %></td></tr>
<% } %>
} catch (Exception ex) {
Ooops, somthing bad happened:
} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();

** employees is the name of the database.
bernd pier
Ranch Hand

Joined: Jun 21, 2002
Posts: 30
hi andrew,
when you use the same file for windows and linux, you must remember, that in linux the slashes are different then in windows
here is an excerpt from my code that runs on linux:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
String loginUser = "root";
String loginPasswd = "";
String loginUrl = "jdbc:mysql://localhost:3306/Coffees";
response.setContentType("text/html"); // Response mime type
// Output stream to STDOUT
PrintWriter out = response.getWriter();
out.println("<BODY bgcolor=#0099ff><H1>COFFEES</H1>");
// Load the mm.MySQL driver
catch (java.lang.ClassNotFoundException e)
System.err.println("ClassNotFoundException: ");
Connection dbcon =DriverManager.getConnection(loginUrl, loginUser, loginPasswd);
// Declare our statement
after //localhost i have the port of the connection to the database(default is 3306).
i hope that will help you a little.
so have a nice day
[ July 10, 2002: Message edited by: bernd pier ]
I agree. Here's the link:
It's not a secret anymore!