|
-
November 1st, 2006, 09:16 AM
#1
[RESOLVED] NullPointerException at doGet line 63
Greetings Java people!
In my effort to understand the process of dealing with databases and web pages I am trying to execute a simple class that hopefully will display the contents back to a JSP page. However, I am getting an “java.lang.NullPointerExeception”
At SQL.SQLGatewayServlet.doGet(SQLGatewayServlet.java:63)
Code:
package SQL;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import util.*;
public class SQLGatewayServlet extends HttpServlet
{
private Connection connection;
private String file;
private String dbDriver;
private String dbURL;
private String dbUser;
private String dbPassword;
public void init() throws ServletException
{
ServletConfig config = getServletConfig();
file = config.getInitParameter("fileName");
dbDriver = config.getInitParameter("jdbcDriver");
dbURL = config.getInitParameter("dbUrl");
dbUser = config.getInitParameter("username");
dbPassword = config.getInitParameter("password");
try
{
Class.forName(dbDriver);
connection = DriverManager.getConnection(dbURL,dbUser,dbPassword);
}
catch (ClassNotFoundException e)
{
System.out.println("Database Driver Not Found ");
}
catch (SQLException e)
{
System.out.println("Error Opening the DB connection: " + e.getMessage());
}
}
public void destroy()
{
try
{
connection.close();
}
catch (SQLException e)
{
System.out.println("Error closing the db connection: " + e.getMessage());
}
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String sqlStatement = request.getParameter("sqlStatement");
String message = "";
try
{
Statement statement = connection.createStatement();
sqlStatement = sqlStatement.trim();
String sqlType = sqlStatement.substring(0,6);
if(sqlType.equalsIgnoreCase("select"))
{
ResultSet resultSet = statement.executeQuery(sqlStatement);
message = SQLUtil.getHtmlRows(resultSet);
}
else
{
int i = statement.executeUpdate(sqlStatement);
if(i == 0)
message = "The statement executed successfully.";
else
message = "The statement executed successfully.<br/>" + i + "row(s) affected.";
}
statement.close();
}
catch(SQLException e)
{
message = "Error executing the SQL statement: <br>" + e.getMessage();
}
HttpSession session = request.getSession();
session.setAttribute("message", message);
session.setAttribute("sqlStatement", sqlStatement);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/jsp/sql_gateway.jsp");
dispatcher.forward(request, response);
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}
Is the application getting the parameter from my jsp or am I overlooking something.
Thanks for any assistance in this area. It would be nice to have some sort of debugger for this stuff. Developing in C I can step through line by line. Don’t know how to do that using Java
Best regards,
Steve…
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|