This code has a lot wrong with it and is not even a servlet!! Giving you the
benefit of the doubt and assuming that you want it to be a servlet then:
1. Declare the class as a servlet as follows. Otherwise stop posting to this
mailing list!
public class dbtest extends HttpServlet {
public void doGet (
HttpServletRequest request,
HttpServletResponse response
) throws ServletException, IOException
Also...
2. Use the correct imports, that is:
import java.sql.*;
import java.io.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;
3. Set up the response Header and get the writer...
response.setContentType("text/vnd.wap.wml");
PrintWriter out = response.getWriter();
4. Regarding Exception java.lang.ClassNotFoundException then do as the
error says, ie catch the exception!
Hope this helps,
Andy
> ----- Original Message -----
> From: wap@asl <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, July 24, 2000 1:15 PM
> Subject: JDBC
>
>
> > Hi All,
> >
> > I have started development in servlets recently. Facing problem while
> > establishing connection with Access & SQL databases using JDBC driver.
> >
> > my Classpath:
> > CLASSPATH=.;c:\jsdk2.1\servlet.jar
> >
> > My code:
> > public class dbtest {
> > public static void main() throws SQLException {
> >
> > Class.forName("jdbc.odbc.JdbcOdbcDriver");
> > Connection con = DriverManager.getConnection("jdbc:odbc:helpline.dsn",
> "",
> > "");
> >
> > Statement stmt = con.createStatement();
> > ResultSet rs = stmt.executeQuery ("SELECT * FROM cities");
> >
> > while (rs.next())
> > {
> > out.println(rs.getString("pin"));
> > }
> > }
> > };
> >
> > The error:
> > D:\mobile\scripts>javac dbtest.java
> > dbtest.java:2: Class SQLException not found in throws.
> > public static void main() throws SQLException {
> > ^
> > dbtest.java:4: Exception java.lang.ClassNotFoundException must be
caught,
> or
> > it must be declared in the throws claus
> > e of this method.
> > Class.forName("jdbc.odbc.JdbcOdbcDriver");
> > ^
> > dbtest.java:5: Class Connection not found.
> > Connection con =
> > DriverManager.getConnection("jdbc:odbc:helpline.dsn", "", "");
> > ^
> > dbtest.java:5: Undefined variable or class name: DriverManager
> > Connection con =
> > DriverManager.getConnection("jdbc:odbc:helpline.dsn", "", "");
> > ^
> > dbtest.java:7: Class Statement not found.
> > Statement stmt = con.createStatement();
> > ^
> > dbtest.java:8: Class ResultSet not found.
> > ResultSet rs = stmt.executeQuery ("SELECT * FROM
cities");
> > ^
> > dbtest.java:12: Undefined variable or class name: out
> > out.println(rs.getString("pin"));
> > ^
> > 7 errors
> >
> >
> > What might be wrong? Do I need to add anything to my CLASSPATH?
> >
> > Thanx & Regards,
> >
> > Kaushal.
> >
> >
>
___________________________________________________________________________
> > 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