MySQL Driver Error on Linux Tutorial Example
843835Jun 24 2002 — edited Jun 30 2002I am using the tutorial at
http://www.yolinux.com/TUTORIALS/LinuxTutorialTomcat.html#MYSQL, but I
get the error: SQL error in doGet: org.gjt.mm.mysql.Driver
Does this have something to do with the way I set up SQL? Any idea how
I can fix it? I am new to mySQL, so please provide the commands to
any solutions.
Unlike in the examples' 'Potential Pittfalls' section, when I 'select
user, host from user' in my sql, I get:
--------------------------+
| user | host |
--------------------------+
| Dude1 | % |
| tester | % |
| | localhost |
|root | localhost |
| |localhost.localdomain|
|root |localhost.localdomain|
|Dude1 |superserver |
|tester |superserver |
--------------------------
Here's my exact java code for the servlet (i have tried changing the
name and password to use root, tester, Dude1, etc.).
// File: ShowBedrock.java
/* A servlet to display the contents of the MySQL Bedrock database */
import java.io.*;
import java.net.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ShowBedrock extends HttpServlet
{
public String getServletInfo()
{
return "Servlet connects to MySQL database and displays result
of a SELECT";
}
// Use http GET
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws IOException, ServletException
{
String loginUser = "Dude1";
String loginPasswd = "SuperSecret";
String loginUrl = "jdbc:mysql://localhost:3306/bedrock";
response.setContentType("text/html"); // Response mime type
// Output stream to STDOUT
PrintWriter out = response.getWriter();
out.println("<HTML><HEAD><TITLE>Bedrock</title></head>");
out.println("<BODY><H1>Bedrock</h1>");
// Load the mm.MySQL driver
try
{
Class.forName("org.gjt.mm.mysql.Driver");
Connection dbcon = DriverManager.getConnection(loginUrl,
loginUser, loginPasswd);
// Declare our statement
Statement statement = dbcon.createStatement();
String query = "SELECT name, dept, ";
query += " jobtitle ";
query += "FROM employee ";
// Perform the query
ResultSet rs = statement.executeQuery(query);
out.println("<TABLE border>");
// Iterate through each row of rs
while (rs.next())
{
String m_name = rs.getString("name");
String m_dept = rs.getString("dept");
String m_jobtitle = rs.getString("jobtitle");
out.println("<tr>" +
"<td>" + m_name + "</td>" +
"<td>" + m_dept + "</td>" +
"<td>" + m_jobtitle + "</td>" +
"</tr>");
}
out.println("</table>");
rs.close();
statement.close();
dbcon.close();
}
catch (SQLException ex) {
while (ex != null) {
System.out.println ("SQL Exception: " +
ex.getMessage ());
ex = ex.getNextException ();
} // end while
} // end catch SQLException
catch(java.lang.Exception ex)
{
out.println("<HTML>" +
"<HEAD><TITLE>" +
"Bedrock: Error" +
"</title></head>\n<BODY>" +
"<P>SQL error in doGet: " +
ex.getMessage() + "</p></body></html>");
return;
}
out.close();
}
}
(crossposted at: http://groups.google.com/groups?q=testingforechoes&hl=en&lr=&ie=UTF-8&oe=UTF8&scoring=d&selm=89584a18.0206230433.68624506%40posting.google.com&rnum=1