Hi Friend,
Thank you so much for your response.
With all your help,I figure out what's wrong ,that classpath must be set to include
the JDBC driver prior to start the java web server.And I need to add Books in
system DSN,not user DSN.
have a nice day to all,
chris
Charles Chen wrote:
> Contact: Tel: 2726 - New Media Systems, 1st Floor South, Queens Walk
>
> if the JWS can load your servlet, the connection should have been established,
> meaning the error is in your SQl statement. To verify this, try to move the
> statement into the init() and use prepareStatement instead. Then try to load it
> again in JWS admin. If you don't pass any userid and password when connecting,
> make sure yuor database is not password protected.
>
> Performance wise, you should use the prepareStatement() anyway.
>
> Charles
>
> Ying Sun <[EMAIL PROTECTED]> on 10/17/2000 06:42:16 PM
>
> To: [EMAIL PROTECTED]
> cc: (bcc: Charles Chen/YellowPages)
> From: Ying Sun <[EMAIL PROTECTED]>, 17 October 2000, 6:42 p.m.
>
> Re: database servlet [Scanned by Yellow Pages PostMaster]
>
> Thank you all,
> I login in javawebserver admin,it can load the JdbcServlet,but in the event log
> it
> give me the message like this:
> ServletManager.loadServlet JdbcServlet:class=JdbcServlet class URL=<none>
> arguments=<none>
>
> does it mean I need to add database url property in configuration?
>
> thanks again,
>
> chris
>
> Charles Chen wrote:
>
> > Contact: Tel: 2726 - New Media Systems, 1st Floor South, Queens Walk
> >
> > I vaguely remember that the connection string is
> > "jdbc:odbc:JdbcOdbcBridge:Books" but I might be wrong. Check this out anyway.
> >
> > In general, you should be able to see the exception when your servlet is
> loaded
> > if that connection string is wrong. If you are using JWS 2.0 (looks ilke it)
> you
> > can login as admin and try to load your servlet from there. If the connection
> > string is wrong, it will fail to load your servlet.
> >
> > Charles
> >
> > Ying Sun <[EMAIL PROTECTED]> on 10/17/2000 05:10:37 PM
> >
> > To: [EMAIL PROTECTED]
> > cc: (bcc: Charles Chen/YellowPages)
> > From: Ying Sun <[EMAIL PROTECTED]>, 17 October 2000, 5:10 p.m.
> >
> > Re: database servlet [Scanned by Yellow Pages PostMaster]
> >
> > Hi friends,
> >
> > I create the data source Books.mdb as a System DSN on my machine,and I
> > try to use JdbcServlet to retrieve the data from the Arthurs table.
> >
> > when I invoke it using http://localhost:8080/servlet/JdbcServlet,it gave
> > me blank page.I use java web server2.0.
> >
> > Can someone give me a idea?
> >
> > thanks.
> >
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> > import java.io.*;
> > import java.sql.*;
> >
> > /**
> > * JdbcServlet reads customer information from an ODBC data
> > * source and presents it to the client in an HTML table.
> > *
> > */
> > public class JdbcServlet extends HttpServlet
> > {
> > //database connection is shared by all requests
> > static Connection dbConn;
> >
> > /**
> > * init method is called when servlet is initialized.
> > * Establishes a database connection when servlet is initially
> > * loaded that can be shared across all requests.
> > */
> > public void init(ServletConfig config) throws
> > ServletException
> > {
> > super.init(config); //pass ServletConfig to parent
> >
> > try
> > {
> > //load JDBC-ODBC Bridge driver
> > Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
> > //establish database connection to Books using ODBC
> > dbConn = DriverManager.getConnection(
> > "jdbc:odbc:Books");
> > }
> > catch (ClassNotFoundException e) //Class.forName throws
> > {
> > System.out.println("JDBC-ODBC bridge not found!");
> > return;
> > }
> > catch (SQLException e) //DriverManager.getConnection throws
> > {
> > System.out.println("SQL exception thrown in init!");
> > return;
> > }
> > }
> >
> > /**
> > * doGet method is called in response to a GET request
> > */
> > public void doGet(HttpServletRequest request,
> > HttpServletResponse response) throws ServletException,
> > IOException
> > {
> > try
> > {
> > response.setContentType("text/html"); //returns HTML
> >
> > //get handle to output stream
> > PrintWriter out = response.getWriter();
> >
> > //create statement
> > Statement stat = dbConn.createStatement();
> > //query database for result set
> > ResultSet customers = stat.executeQuery(
> > "SELECT AuthorID, FirstName, LastName, YearBorn FROM " +
> > "Authors");
> >
> > //generate HTML document to return to client
> > out.println("<HTML>");
> > out.println("<HEAD><TITLE>author list</TITLE></HEAD>");
> > out.println("<BODY>");
> > out.println("<H2>author List</H2>");
> > out.println("<TABLE BORDER=1>"); //create an HTML table
> > out.println("<TR><TH>Author ID</TH>");
> > out.println("<TH>first Name</TH>");
> > out.println("<TH>last name</TH>");
> > out.println("<TH>year born</TH></TR>");
> >
> > while (customers.next()) //iterate through all records
> > {
> > //add a table row for each record
> > out.println("<TR><TD>" +
> > customers.getInt("AuthorID")+ "</TD><TD>" +
> > customers.getString("FirstName") + "</TD><TD>" +
> > customers.getString("LastName") + "</TD><TD>" +
> > customers.getString("YearBorn") + "</TD></TR>");
> > }
> >
> > out.println("</TABLE>");
> > out.println("</BODY></HTML>");
> > out.close();
> > }
> > catch (Exception e)
> > {
> > e.printStackTrace();
> > }
> > }
> >
> > /**
> > * Tells the server about this servlet
> > */
> > public String getServletInfo()
> > {
> > return "Sample JDBC servlet";
> > }
> > }
> >
> > ___________________________________________________________________________
> > 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
>
> ___________________________________________________________________________
> 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
___________________________________________________________________________
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