<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%

Statement stmt =null;
Connection conn =null;
ResultSet rs = null;

try
{
String url = "jdbc:oracle:thin:@ahmad:1521:PLSExtProc";
String user = "training";
String password = "training";
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("--------------");
//Get a connection to the database
conn = DriverManager.getConnection(url, user, password);
//Get a statement from the connection
stmt = conn.createStatement();

}
catch(Exception ex)
{
	System.out.println("Error in creating the connection  :"+ex.getMessage());
}





try
{
	String Query="";

	Query="select * from employee; ";
	System.out.println("Query========================="+Query);

	String id ="";
	String name ="";
	//Execute the Query and return the resultSet
	rs= stmt.executeQuery(Query);

	while (rs.next())
	{

		name = rs.getString("*");

	}


rs.close();
}

catch (Exception exp)
{
   System.out.println("there was an error building the xml file " + exp.getMessage());
}

finally
{
   stmt.close();
   conn.close();
}
%>

I am getting this error. what is it?

500 Internal Server Error
java.lang.NullPointerException at _untitled9._jspService(_untitled9.java:106) [/untitled9.jsp] at com.orionserver[Oracle Containers for J2EE 10g (10.1.3.3.0) ].http.OrionHttpJspPage.service(OrionHttpJspPage.java:59) at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:462) at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594) at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518) at javax.servlet.http.HttpServlet.service(HttpServlet.java:856) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:713) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:122) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:111) at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260) at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:239) at oracle.oc4j.network.ServerSocketAcceptHandler.access$700(ServerSocketAcceptHandler.java:34) at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:880) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:298) at java.lang.Thread.run(Thread.java:595)

ORCL =
(DESCRIPTION =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = ahmad)
(PORT = 1521)
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)


EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = IPC)
(KEY = EXTPROC1)
)
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)


And thats my tnsnameseditor in toadq

Using tomcat, its handing me this error

org.apache.jasper.JasperException: An exception occurred processing JSP page /new 6.jsp at line 67


org.apache.jasper.JasperException: An exception occurred processing JSP page /new 6.jsp at line 67

64: finally
65: {
66:   //if(stmt != null)
67:   stmt.close();
68:    //if(conn != null)
69:    conn.close();
70: }


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.lang.NullPointerException
    org.apache.jsp.new_00206_jsp._jspService(new_00206_jsp.java:122)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

i worked it out.

<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%

Statement stmt =null;
Connection conn =null;
//Statement stmt;
//Connection conn;
ResultSet rs = null;

try
{
String url = "jdbc:oracle:thin:@ahmad:1521:ORCL";
String user = "training";
String password = "training";
Class.forName("oracle.jdbc.driver.OracleDriver");
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Class.forName("Oracle.jdbc.odbc.OracleOdbcDriver").newInstance(); 
System.out.println("--------------");
//Get a connection to the database
conn = DriverManager.getConnection(url, user, password);
//Get a statement from the connection
stmt = conn.createStatement();

}
catch(Exception ex)
{
	System.out.println("Error in creating the connection  :"+ex.getMessage());
}




try
{
	String Query="";

	Query="select name from employee ";
	System.out.println("Query========================="+Query);

	String id ="";
	String name ="";
	//Execute the Query and return the resultSet
	rs= stmt.executeQuery(Query);
                       
	while (rs.next())
	{

		name = rs.getString("name");

	}


rs.close();
}

catch (Exception exp)
{
   System.out.println("Error in Query execution " + exp.getMessage());
}

finally
{
  //if(stmt != null)
  stmt.close();
   //if(conn != null)
   conn.close();
}
%>

I had service name wrong + the query was wrong

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.