
my code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>hi to all</title>
</head>
<body>
Hi this is my page
<%
Connection conn = null;
String userName = "root";
String password = "";
String url = "jdbc:mysql://localhost/interviewer";
System.out.println(url);
System.out.println("username="+userName+", password=" +""+password);
Class.forName ("com.mysql.jdbc.Driver").newInstance ();//it shows error this line
conn = DriverManager.getConnection (url, userName, password);
Statement select = conn.createStatement();
ResultSet result = select.executeQuery ("SELECT username,password FROM login where login_id=212");
System.out.println("Got results:");
while(result.next()) { // process results one row at a time
String username = result.getString(1);
String pwd = result.getString(2);
System.out.println("userid = " +username );
System.out.println("password= " + pwd);
}
%>
</body>
</html>
______________________end of the code-----------------------------------------------
i got this error
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /mypage.jsp at line 20
17: String url = "jdbc:mysql://localhost/interviewer";
18: System.out.println(url);
19: System.out.println("username="+userName+", password=" +""+password);
20: Class.forName ("com.mysql.jdbc.Driver").newInstance ();
21: conn = DriverManager.getConnection (url, userName, password);
22: Statement select = conn.createStatement();
23: ResultSet result = select.executeQuery ("SELECT username,password FROM login where login_id=212");
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
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:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.mypage_jsp._jspService(mypage_jsp.java:105)
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:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
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:1701)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:169)
org.apache.jsp.mypage_jsp._jspService(mypage_jsp.java:83)
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:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.25 logs.
Apache Tomcat/7.0.25

Please visit the following links:
http://www.roseindia.net/jsp/connect-jsp-mysql.shtml
http://www.roseindia.net/jsp/Accessingdatabase-fromJSP.shtml
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.