aspose file tools*
The moose likes JDBC and the fly likes org.gjt.mm.mysql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "org.gjt.mm.mysql" Watch "org.gjt.mm.mysql" New topic
Author

org.gjt.mm.mysql

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 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

Joined: Nov 12, 2001
Posts: 178
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

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("<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 ]
 
 
subject: org.gjt.mm.mysql