Fejl..NullPointerException
Hej,Jeg har prøvet og find en NullPointerException
fejl i nedstående kode men kunne ik! Er der nogen der kan se fejlen :-)
-----------------------
import java.io.*;
import java.sql.*;
public class MakeConnection{
Statement st;
Connection con;
ResultSet result;
public MakeConnection()
{
}
//Method to make connection to mysql RaceRunner database
public void GetConnection(){
/* connect (commented out strings use classic MySQL driver) */
try {
Class.forName("org.gjt.mm.mysql.Driver");
this.con = DriverManager.getConnection("jdbc:mysql://localhost/RaceRunner", "shemeri", "racerunner");
}
catch (java.sql.SQLException e){
System.out.println("ERROR" + e);
}
catch (Exception e) {
System.out.println("ERROR" + e);
}
}
public void close(){
if (this.con!=null){
try
{
this.con.close();
this.con=null;
}//try
catch (SQLException e)
{
e.printStackTrace(System.out);
}//catch
}//if
}//close()
public void MakeRegister(String RegisterStatement){
GetConnection();
if(this.con!=null){
try {
this.st = this.con.createStatement();
this.st.executeUpdate(RegisterStatement);
}
catch (Exception e) {
System.out.println("ERROR" + e);
}
}//if
}
public void MakeQuery(String QueryStatement){
GetConnection();
if(con!=null){
try {
this.st = this.con.createStatement();
this.result = this.st.executeQuery(QueryStatement);
}
catch (Exception e) {
System.out.println("ERROR" + e);
}
}//if
}
public ResultSet Result(){
return this.result;
}
}
------------------------------------
500 Servlet Exception
java.lang.NullPointerException
at _test2__jsp._jspService(/test2.jsp:13)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.subservice(Page.java:485)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
at com.caucho.server.http.Invocation.service(Invocation.java:312)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:221)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
at java.lang.Thread.run(Thread.java:536)
-------------------------------------
jeg har prøvet og køre denne jsp fil:
<%@page import="java.sql.*"%>
<jsp:useBean id="Connection" scope="session" class="MakeConnection" />
<%
String Person;
Person = "SELECT * from person WHERE Person_ID = 101";
Connection.MakeQuery(Person);
while (Connection.Result().next()){
out.println(Connection.Result().getString(1));
out.println(Connection.Result().getString(2));
out.println(Connection.Result().getString(3));
out.println(Connection.Result().getString(4));
}