• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

org.gjt.mm.mysql

 
bernd pier
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey andrew,
at first, if you want to connect to a database from a servlet you need a driver.mm.mysql is a driver for mysql database, you can download it from www.mmmysql.sourceforge.net (if you want to see all mysql drivers, go to the mysql page).
when you unpack the driver org.gjt.mm.mysql is a directory and the place the Driver.java 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 sourceforge.net hope it will help you.
if there are problems feel free to ask, somebody will help you, maybe i?
bernd
 
Andrew Parker
Ranch Hand
Posts: 178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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:
<html>
<head><title>Employee List</title></head>
<body>
<%@ 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 {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn=DriverManager.getConnection("jdbc:mysql://localhost/employees");
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 (Exception ex) {
ex.printStackTrace();
%>
</table>
Ooops, somthing bad happened:
<%
} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();
}
%>
</body>
</html>

** employees is the name of the database.
 
bernd pier
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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("<HTML><HEAD><TITLE>Coffees</TITLE></HEAD>");
out.println("<BODY bgcolor=#0099ff><H1>COFFEES</H1>");
// Load the mm.MySQL driver
try
{
Class.forName("org.gjt.mm.mysql.Driver");
}
catch (java.lang.ClassNotFoundException e)
{
System.err.println("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
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
bernd
[ July 10, 2002: Message edited by: bernd pier ]
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic