You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by hari hari <ha...@hotmail.com> on 2002/09/25 18:30:48 UTC
simplest Servlet-jdbc not working
hi,
i having simplest of Servlet program (DBServlet.java) which is trying to
connecting to my ORCL DB.
my Application and DB Server are sit on different machines. I having my JDBC
Drivers (in ZIP format) on my App Server installed with CLASSPATH.
when I trying to run i getting below errors: police helping me
# java DBServlet
Exception in thread "main" java.lang.NoSuchMethodError: main
#
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DBServlet extends HttpServlet {
private Connection con;
private PrintWriter out;
private String url = "jdbc:oracle:thin:@MY_IP_ADDRESS:1521:MY_SID";
public void init(ServletConfig conf)
throws ServletException {
super.init(conf);
try{
//Class.forName("oracle.jdbc.OracleDriver");
//con =DriverManager.getConnection(url, "scott", "tiger");
}catch(Exception e) {
System.err.println(e);
}
}
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
try {
out = res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title> Sample JDBC Servlet Demo" + "</title>");
out.println("</head>");
out.println("<body>");
Class.forName("oracle.jdbc.OracleDriver");
con =DriverManager.getConnection(url, "scott", "tiger");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from emp");
out.println("<UL>");
while(rs.next()) {
out.println("<LI>" + rs.getString("EName"));
}
out.println("</UL>");
rs.close();
stmt.close();
} catch(Exception e) { System.err.println(e); }
out.println("</body>");
out.println("</html>");
out.close();
}
--
HARI
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: simplest Servlet-jdbc not working
Posted by Jacob Kjome <ho...@visi.com>.
Hello hari,
Are you trying to run this on the command line or something? That is
the only reason I can think of for it trying to run "main".
Jake
Wednesday, September 25, 2002, 11:30:48 AM, you wrote:
hh> hi,
hh> i having simplest of Servlet program (DBServlet.java) which is trying to
hh> connecting to my ORCL DB.
hh> my Application and DB Server are sit on different machines. I having my JDBC
hh> Drivers (in ZIP format) on my App Server installed with CLASSPATH.
hh> when I trying to run i getting below errors: police helping me
hh> # java DBServlet
hh> Exception in thread "main" java.lang.NoSuchMethodError: main
hh> #
hh> import java.io.*;
hh> import java.sql.*;
hh> import javax.servlet.*;
hh> import javax.servlet.http.*;
hh> public class DBServlet extends HttpServlet {
hh> private Connection con;
hh> private PrintWriter out;
hh> private String url = "jdbc:oracle:thin:@MY_IP_ADDRESS:1521:MY_SID";
hh> public void init(ServletConfig conf)
hh> throws ServletException {
hh> super.init(conf);
hh> try{
hh> //Class.forName("oracle.jdbc.OracleDriver");
hh> //con =DriverManager.getConnection(url, "scott", "tiger");
hh> }catch(Exception e) {
hh> System.err.println(e);
hh> }
hh> }
hh> public void service(HttpServletRequest req, HttpServletResponse res)
hh> throws ServletException, IOException {
hh> res.setContentType("text/html");
hh> try {
hh> out = res.getWriter();
hh> out.println("<html>");
hh> out.println("<head>");
hh> out.println("<title> Sample JDBC Servlet Demo" + "</title>");
hh> out.println("</head>");
hh> out.println("<body>");
hh> Class.forName("oracle.jdbc.OracleDriver");
hh> con =DriverManager.getConnection(url, "scott", "tiger");
hh> Statement stmt = con.createStatement();
hh> ResultSet rs = stmt.executeQuery("select * from emp");
hh> out.println("<UL>");
hh> while(rs.next()) {
hh> out.println("<LI>" + rs.getString("EName"));
hh> }
hh> out.println("</UL>");
hh> rs.close();
hh> stmt.close();
hh> } catch(Exception e) { System.err.println(e); }
hh> out.println("</body>");
hh> out.println("</html>");
hh> out.close();
hh> }
hh> --
hh> HARI
hh> _________________________________________________________________
hh> Send and receive Hotmail on your mobile device: http://mobile.msn.com
hh> --
hh> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
hh> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
Best regards,
Jacob mailto:hoju@visi.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>