Hi:
I has received your suggetion about why my JDBC-Servlet not to
work,and set the variable conn to a public one,the code is following:
import java.sql.*;
import java.io.*;
import java.util.Date;
import javax.servlet.*;
import javax.servlet.http.*;
public class SJdbcTest extends HttpServlet {
private Connection conn=null;
public void init(ServletConfig conf) throws ServletException {
super.init(conf);
try {
Class.forName ("oracle.jdbc.driver.OracleDriver");}
catch (ClassNotFoundException e)
{System.out.println ("Could not load the driver");
e.printStackTrace ();
}
try{
conn
=DriverManager.getConnection("jdbc:oracle:oci7:","scott","tiger");}
catch(SQLException e){System.out.println ("Could not connect
to the driver"); }
System.out.println("init ok!");
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
ServletOutputStream out = res.getOutputStream();
try{
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("select ename from emp");
res.setContentType("text/html");
out.println("<HEAD><TITLE> SJdbcTest </TITLE></HEAD><BODY>");
out.println("<h1> SJdbcTest </h1>");
while (rset.next ())
out.println(rset.getString (1));
out.println("</BODY>");
out.close();
rset.close();
stmt.close();
conn.close();}catch(SQLException e){System.out.println ("Could
not execute SQL"); }
}
public String getServletInfo() {
return "SJdbcTest";
}
}
However it has the same question.I debug it carefully and find that
the loading and connecting to JDBC class is right while the code
'Statement stmt = conn.createStatement (); ' has a exception.SO rset
is null and throw 'NullPointerException'.
I has another question:Why my browser's Java Cotrol(Explore4.0 and
Netscape4.0)doesn't show the infomation which System.out.println()
gives.
I hope you give me further infomation.
Thanks in advance.
HuYong
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html