When I Try To Compile The Following Code It Gives Error I Don't Know Why . . I'm Totally A Newbie to Java & JSP
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class HelloWorldExample extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection DB_CONNECTION = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root;password=");
Statement DB_STATEMENT = DB_CONNECTION.createStatement();
ResultSet RS = DB_STATEMENT.executeQuery("SELECT * FROM test ORDER BY test_id");
String x="";
int y=1;
while (RS.next()) {
x=RS.getString("test_name");
if(x.length()>4){
out.print(x.substring(3)+"<br />");
}
}
}
}
I Got The Following Errors:
HelloWorldExample.java:24: unreported exception java.lang.ClassNotFoundException
; must be caught or declared to be thrown
Class.forName("com.mysql.jdbc.Driver").newInstance();
^
HelloWorldExample.java:24: unreported exception java.lang.InstantiationException
; must be caught or declared to be thrown
Class.forName("com.mysql.jdbc.Driver").newInstance();
^
HelloWorldExample.java:25: unreported exception java.sql.SQLException; must be c
aught or declared to be thrown
Connection DB_CONNECTION = DriverManager.getConnection("jdbc:mysql://loc
alhost:3306/test?user=root;password=");
^
HelloWorldExample.java:26: unreported exception java.sql.SQLException; must be c
aught or declared to be thrown
Statement DB_STATEMENT = DB_CONNECTION.createStatement();
^
HelloWorldExample.java:29: unreported exception java.sql.SQLException; must be c
aught or declared to be thrown
ResultSet RS = DB_STATEMENT.executeQuery("SELECT * FROM test ");
^
HelloWorldExample.java:32: unreported exception java.sql.SQLException; must be c
aught or declared to be thrown
while (RS.next()) {
^
HelloWorldExample.java:33: unreported exception java.sql.SQLException; must be c
aught or declared to be thrown
x=RS.getString("test_name");
^
7 errors