X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 57405565AC for ; Sat, 12 Mar 2005 04:35:36 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 89633-10 for ; Sat, 12 Mar 2005 04:35:30 +0000 (GMT) Received: from web14924.mail.yahoo.com (web14924.mail.yahoo.com [216.136.225.8]) by svr1.postgresql.org (Postfix) with SMTP id 011BD566C1 for ; Sat, 12 Mar 2005 04:35:26 +0000 (GMT) Received: (qmail 6546 invoked by uid 60001); 12 Mar 2005 04:35:25 -0000 Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; b=11jBdAsiv16UDzmuJAUe+dn4lC8giNoSdYmd5GMuTm5rYPKYeW0oWS21ET0a3kxt1+/7VzGdn28qJW1Ki/19NvFS7ozEm3bOvYkPtGVPgyVQjBU7GgiB8DehecvnjtzvXrA1RvdqLystVLEBul1vyFhjV+RXT+xTkoeoBrf5dTs= ; Message-ID: <20050312043525.6544.qmail@web14924.mail.yahoo.com> Received: from [61.246.50.181] by web14924.mail.yahoo.com via HTTP; Fri, 11 Mar 2005 20:35:25 PST Date: Fri, 11 Mar 2005 20:35:25 -0800 (PST) From: Simon Moses Subject: Re: preoblem in jdbc postgresql and tomcat To: java unix Cc: pgsql jdbc In-Reply-To: <20050312040109.71481.qmail@web8405.mail.in.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.374 tagged_above=0 required=5 tests=DNS_FROM_RFC_ABUSE X-Spam-Level: X-Archive-Number: 200503/127 X-Sequence-Number: 12519 hi, some corrections. CLASSPATH my preference of jars in CLASSPATH is tools.jar:pg74.215.jdbc3.jar:others:. see the code change in Class.forName and url. try{ Class.forName("org.postgresql.Driver"); Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/dbname","postgres","postgres"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select col1 from test"); while(rs.next()){ out.println(rs.getString(1)+"
"); } }catch(Exception e){ out.println(e); } if the above code works then you try same in jsp. --Simon Moses. Bangalore, India. --- java unix wrote: > hi, > i have installed postgresql-7.4.1,and > tomcat4.1.31and > j2sdk1.4.2_07 > for tomcat i have included path > /usr/local/jakarta-tomcat-4.1.31 > for j2sdk path set is /usr/local/j2sdk1.4.2_07 > and CLASSPATH SET IS: > /usr/local/pgsql/pg73jdbc3.jar:/usr/local/pgsql/pg74.215.jdbc3.jar:/usr/local/pg > sql/postgresql-8.0-310.jdbc3.jar:/usr/local/j2sdk1.4.2_07/lib/tools.jar:/usr/loc > al/j2sdk1.4.2_07/jre/lib/rt.jar:/usr/local/jakarta-tomcat-4.1.31/common/lib/serv > let.jar:/usr/local/jakarta-tomcat-4.1.31/common/lib:/usr/local/pgsql:/usr/local/ > j2sdk1.4.2_07/jre/lib:/usr/local/j2sdk1.4.2_07/lib > i have included all the paths > > all the above path are set in /etc/profile/ > and i set path for all three jar > files:/usr/local/pgsql/pg73jdbc3.jar:/usr/local/pgsql/pg74.215.jdbc3.jar:/usr/local/pg > sql/postgresql-8.0-310.jdbc3.jar > > when i run this simple java program i get > error as follows: > [root@roopesh bin]# javac > PostgreSQLTest.java//compile > PostgreSQLTest.java: In class `PostgreSQLTest': > PostgreSQLTest.java: In method > `PostgreSQLTest.main(java.lang.String[])': > PostgreSQLTest.java:7: Exception > `java.lang.ClassNotFoundException' must be caught, > or > it must be declared in the `throws' clause of > `main'. > > Class.forName("postgresql.Driver").newInstance(); > ^ > PostgreSQLTest.java:7: Exception > `java.lang.InstantiationException' must be caught, > or > it must be declared in the `throws' clause of > `main'. > > Class.forName("postgresql.Driver").newInstance(); > ^ > PostgreSQLTest.java:7: Exception > `java.lang.IllegalAccessException' must be caught, > or > it must be declared in the `throws' clause of > `main'. > > Class.forName("postgresql.Driver").newInstance(); > > my PostgreSQLTest.java is as below > import java.sql.*; > > > > > > class PostgreSQLTest { > public static void main (String[] args) { > try { > Driver driver = (Driver) > > Class.forName("postgresql.Driver").newInstance(); > DriverManager.registerDriver(driver); > > > > > > String url = "jdbc:postgresql:javatest"; > Connection con = > DriverManager.getConnection(url, "postgres", ""); > Statement stm = con.createStatement(); > > > > > > stm.setQueryTimeout(10); > ResultSet rs = stm.executeQuery("select col1 > from test"); > > > > > > rs.next(); > > > > > > System.out.println(rs.getString(1)); > > > > > > } catch (SQLException e) { > > > > > > System.out.println("Exception!"); > System.out.println(e.toString()); > } > } > } > This is one simple example > > Now when i tried to perform operations with tomcat > simple sevlet works but with database operations i > get > the following errors > file is:ShowBedrock.java > import javax.servlet.*; > import javax.servlet.http.*; > > > > > > public class ShowBedrock extends HttpServlet > { > public String getServletInfo() > { > return "Servlet connects to PostgreSQL > database > and displays result of a SELECT"; > } > > > > > > private Connection dbcon; // Connection for > scope > of ShowBedrock > > > > > > // "init" sets up a database connection > public void init(ServletConfig config) throws > ServletException > { > String loginUser = "postgres"; > String loginPasswd = "roopesh"; > String loginUrl = > "jdbc:postgresql://localhost/bedrock"; > > > > > > // Load the PostgreSQL driver > try > { > > Class.forName("org.postgresql.Driver"); > dbcon = > DriverManager.getConnection(loginUrl, loginUser, > loginPasswd); > } > catch (ClassNotFoundException ex) > { > > System.err.println("ClassNotFoundException: " + > ex.getMessage()); > throw new ServletException("Class not > found Error"); > } > catch (SQLException ex) > { > System.err.println("SQLException: " + > ex.getMessage()); > } > } > > > > // > Use http GET > > > > > > public void doGet(HttpServletRequest request, > HttpServletResponse response) > throws IOException, ServletException > { > response.setContentType("text/html"); // > Response mime type > > > > > === message truncated === ************************** Visit My Home Page http://www.geocities.com/ks_moses updated: 28 Sep 2004. Simon Moses ************************** __________________________________ Do you Yahoo!? Yahoo! Small Business - Try our new resources site! http://smallbusiness.yahoo.com/resources/