Jump to content



Recommended Posts

Dear Friends I have a unique problem in java, when i try to connect to mysql db.It shows an error message:

Unable to load driver. Getting Connection ... SQLException: No suitable driver
I am using mysql MySQL 4.1.9 and tomcat 5.5 version.though i have loaded the driver in lib directory, it still displays the same errormessgae. Here is the jsp file which i use to connect to my database.http://localhost:8080/mysqljdbc.jsp
<%@ page import="java.net.*" %><%@ page import="java.util.*" %><%@ page import="java.io.*" %><%@ page import="java.sql.*" %><% try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (Exception E) { out.println("Unable to load driver."); E.printStackTrace(); } try{ out.println("Getting Connection ..."); Connection C = DriverManager.getConnection("jdbc:mysql://localhost:3306/vinoth"); out.println("<br>Connected: " + !C.isClosed() + "<br>\n"); out.println("Catalog: " + C.getCatalog() + "<br>\n"); Statement S = C.createStatement(); ResultSet rs = S.executeQuery("SELECT * FROM foo"); ResultSetMetaData rsStruc = rs.getMetaData(); out.println("Table: " + rsStruc.getTableName(1) + "<br>"); out.println("<table bgcolor=c8c8c8 cellpadding=5 cellspacing=1>"); out.println("<tr bgcolor=000000>"); int colCount = rsStruc.getColumnCount(); String colName = ""; for(int i=1;i <= colCount; i++){ colName = rsStruc.getColumnName(i) ; out.println("<td><B><font color=white>" + colName + "</font></b></td>\n"); } out.println("</tr>"); while (rs.next()) { out.println("<tr bgcolor=ffffff>"); for(int i=1;i <= colCount; i++){ colName = rsStruc.getColumnName(i) ; String fld = rs.getString(colName); out.println("<td>" + fld + "</td>"); } out.println("</tr>"); } out.println("</table>"); rs.close(); C.close(); } catch (Exception E) { out.println("SQLException: " + E.getMessage()); } %>
Now is there anything i have to configure apart from this.Thanx in advance.
Link to comment
Share on other sites

When I was programming in Java with MySQL and Tomcat, it seemed like 95% of the problems I ran into were because I forgot to add some path to my CLASSPATH environment variable. Are you referencing the MySQL driver in your CLASSPATH?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...