hi,
just change one line and try out.
Connection conn =
DriverManager.getConnection("jdbc:oracle:oci7:@DatabaseAlias","scott","tiger");
DatabaseAlias is the one which you create through SqlNet. Hope this helps you.
Regards Nitin.
yong hu wrote:
> Hi:
> I has write a JDBC-Servlet file,but it doesn't work,the error
> information in the browser is 'having a internal server error' and
> exception is 'Java.lang.NullPointerException'. I use oracle7.3 RDBS
> ,oci7 JDBC Driver and SUN Java Web Server.
> The following is my code:
>
> 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;
> 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{
> Connection conn =
> DriverManager.getConnection("jdbc:oracle:oci7:scott/tiger");
> }catch(SQLException e){System.out.println ("Could not connect to
> the driver"); }
> }
>
> public void doGet (HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException
> {
> try{
> Statement stmt = conn.createStatement ();
> ResultSet rset = stmt.executeQuery ("select ename from emp");
>
> ServletOutputStream out = res.getOutputStream();
>
> 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";
> }
> }
>
> I assure that the classpath is right,because there is no error when
> I compile it.
> Thanks in advance.
> Regards.
>
> 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
___________________________________________________________________________
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