Hi all,
Class.forName(driver) errors with the following
Is there anything i am missing here?
Code:
Connection conn = null;
String url = "jdbc:mysql:///mysql12.000webhost.com\\";
String dbName = "example";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try
{
Class.forName(driver).newInstance();
out.println(url+dbName +userName +password);
conn = DriverManager.getConnection(url+dbName, userName,password);
try
{
Statement st = conn.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM table1");
out.println("Emp_code: " + "\t" + "Emp_name: ");
while (res.next())
{
String s = res.getString("userid");
String name = res.getString("Name");
out.println(s + "\t\t" + name);
}
}
catch (SQLException s)
{
out.println("SQL code does not execute.");
}
conn.close();
}
catch (Exception e)
{
}
Class.forName(driver) errors with the following
Code:
org.apache.jasper.JasperException: An exception occurred processing JSP page /heading.jsp at line 19
19: Class.forName(driver).newInstance();
20: out.println(url+dbName +userName +password);
21: conn = DriverManager.getConnection(url+dbName, userName,password);
22:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:551)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:440)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:915)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:844)
org.apache.jsp.index_jsp._jspService(index_jsp.java:173)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.apache.jsp.index_jsp._jspService(index_jsp.java:94)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
Is there anything i am missing here?