pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedError while trying to connect to postgresql
4+ messages / 2 participants
[nested] [flat]
* Error while trying to connect to postgresql
@ 2006-12-29 07:15 Danish Siddiqui <dsiddiqui@vertex.co.in>
0 siblings, 2 replies; 4+ messages in thread
From: Danish Siddiqui @ 2006-12-29 07:15 UTC (permalink / raw)
To: pgsql-jdbc
Hi,
Can some one help me out with this problem. Ive been searching around
for some help but couldnt find any...
Im trying to connect PostgreSQL with Java..
import java.sql.*;
class PostgreSQLTest{
public static void main(String[] args){
Class.forName("org.postgresql.Driver");
String url="jdbcostgresql://localhost/postgres";
Connection db = DriverManager.getConnection("url", "postgres", "");
System.out.println("Connection Created");
db.close();
}
}
# javac PostgreSQLTest.java
PostgreSQLTest.java:5: unreported exception
java.lang.ClassNotFoundException; must be caught or declared to be thrown
Class.forName("org.postgresql.Driver");
^
PostgreSQLTest.java:7: unreported exception java.sql.SQLException; must
be caught or declared to be thrown
Connection db = DriverManager.getConnection("url", "postgres", "");
^
PostgreSQLTest.java:10: unreported exception java.sql.SQLException; must
be caught or declared to be thrown
db.close();
^
3 errors
# echo $CLASSPATH
:/usr/local/jdk1.6.0/lib/tools.jar:/usr/local/pgsql/share/java/postgresql-8.1-408.jdbc3.jar:/usr/local/jdk1.6.0/lib/:/home/danish/:/home/danish/PostgreSQLTest.java
Thanks
Danish
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Error while trying to connect to postgresql
@ 2006-12-29 09:07 Xavier Poinsard <xpoinsard@free.fr>
parent: Danish Siddiqui <dsiddiqui@vertex.co.in>
1 sibling, 1 reply; 4+ messages in thread
From: Xavier Poinsard @ 2006-12-29 09:07 UTC (permalink / raw)
To: Danish Siddiqui <dsiddiqui@vertex.co.in>; +Cc: pgsql-jdbc
Hi,
Your url is wrong. It should look like
"jdbc:postgresql://localhost/postgres".
See http://jdbc.postgresql.org/documentation/82/connect.html for more info.
Regards.
Danish Siddiqui a écrit :
> Hi,
> Can some one help me out with this problem. Ive been searching around
> for some help but couldnt find any...
>
> Im trying to connect PostgreSQL with Java..
>
> import java.sql.*;
>
> class PostgreSQLTest{
> public static void main(String[] args){
> Class.forName("org.postgresql.Driver");
> String url="jdbcostgresql://localhost/postgres";
> Connection db = DriverManager.getConnection("url", "postgres", "");
>
> System.out.println("Connection Created");
> db.close();
> }
> }
>
> # javac PostgreSQLTest.java
>
> PostgreSQLTest.java:5: unreported exception
> java.lang.ClassNotFoundException; must be caught or declared to be thrown
> Class.forName("org.postgresql.Driver");
> ^
> PostgreSQLTest.java:7: unreported exception java.sql.SQLException; must
> be caught or declared to be thrown
> Connection db = DriverManager.getConnection("url", "postgres", "");
> ^
> PostgreSQLTest.java:10: unreported exception java.sql.SQLException; must
> be caught or declared to be thrown
> db.close();
> ^
> 3 errors
>
>
> # echo $CLASSPATH
> :/usr/local/jdk1.6.0/lib/tools.jar:/usr/local/pgsql/share/java/postgresql-8.1-408.jdbc3.jar:/usr/local/jdk1.6.0/lib/:/home/danish/:/home/danish/PostgreSQLTest.java
>
>
> Thanks
> Danish
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Error while trying to connect to postgresql
@ 2006-12-29 09:15 Xavier Poinsard <xpoinsard@free.fr>
parent: Danish Siddiqui <dsiddiqui@vertex.co.in>
1 sibling, 0 replies; 4+ messages in thread
From: Xavier Poinsard @ 2006-12-29 09:15 UTC (permalink / raw)
To: Danish Siddiqui <dsiddiqui@vertex.co.in>; +Cc: pgsql-jdbc
Sorry,
I answered too quickly to your email. Your compilation problem is that
you must catch SQLException and ClassNotFoundException using the java
try-catch syntax.
See http://java.sun.com/docs/books/jls/third_edition/html/exceptions.html
Regards.
Danish Siddiqui a écrit :
> Hi,
> Can some one help me out with this problem. Ive been searching around
> for some help but couldnt find any...
>
> Im trying to connect PostgreSQL with Java..
>
> import java.sql.*;
>
> class PostgreSQLTest{
> public static void main(String[] args){
> Class.forName("org.postgresql.Driver");
> String url="jdbcostgresql://localhost/postgres";
> Connection db = DriverManager.getConnection("url", "postgres", "");
>
> System.out.println("Connection Created");
> db.close();
> }
> }
>
> # javac PostgreSQLTest.java
>
> PostgreSQLTest.java:5: unreported exception
> java.lang.ClassNotFoundException; must be caught or declared to be thrown
> Class.forName("org.postgresql.Driver");
> ^
> PostgreSQLTest.java:7: unreported exception java.sql.SQLException; must
> be caught or declared to be thrown
> Connection db = DriverManager.getConnection("url", "postgres", "");
> ^
> PostgreSQLTest.java:10: unreported exception java.sql.SQLException; must
> be caught or declared to be thrown
> db.close();
> ^
> 3 errors
>
>
> # echo $CLASSPATH
> :/usr/local/jdk1.6.0/lib/tools.jar:/usr/local/pgsql/share/java/postgresql-8.1-408.jdbc3.jar:/usr/local/jdk1.6.0/lib/:/home/danish/:/home/danish/PostgreSQLTest.java
>
>
> Thanks
> Danish
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Error while trying to connect to postgresql
@ 2006-12-29 09:15 Danish Siddiqui <dsiddiqui@vertex.co.in>
parent: Xavier Poinsard <xpoinsard@free.fr>
0 siblings, 0 replies; 4+ messages in thread
From: Danish Siddiqui @ 2006-12-29 09:15 UTC (permalink / raw)
To: Xavier Poinsard <xpoinsard@free.fr>; pgsql-jdbc
Xavier Poinsard wrote:
> Hi,
>
> Your url is wrong. It should look like
> "jdbc:postgresql://localhost/postgres".
> See http://jdbc.postgresql.org/documentation/82/connect.html for more info.
>
> Regards.
>
> Danish Siddiqui a écrit :
>
>> Hi,
>> Can some one help me out with this problem. Ive been searching around
>> for some help but couldnt find any...
>>
>> Im trying to connect PostgreSQL with Java..
>>
>> import java.sql.*;
>>
>> class PostgreSQLTest{
>> public static void main(String[] args){
>> Class.forName("org.postgresql.Driver");
>> String url="jdbcostgresql://localhost/postgres";
>> Connection db = DriverManager.getConnection("url", "postgres", "");
>>
>> System.out.println("Connection Created");
>> db.close();
>> }
>> }
>>
>> # javac PostgreSQLTest.java
>>
>> PostgreSQLTest.java:5: unreported exception
>> java.lang.ClassNotFoundException; must be caught or declared to be thrown
>> Class.forName("org.postgresql.Driver");
>> ^
>> PostgreSQLTest.java:7: unreported exception java.sql.SQLException; must
>> be caught or declared to be thrown
>> Connection db = DriverManager.getConnection("url", "postgres", "");
>> ^
>> PostgreSQLTest.java:10: unreported exception java.sql.SQLException; must
>> be caught or declared to be thrown
>> db.close();
>> ^
>> 3 errors
>>
>>
>> # echo $CLASSPATH
>> :/usr/local/jdk1.6.0/lib/tools.jar:/usr/local/pgsql/share/java/postgresql-8.1-408.jdbc3.jar:/usr/local/jdk1.6.0/lib/:/home/danish/:/home/danish/PostgreSQLTest.java
>>
>>
>> Thanks
>> Danish
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 4: Have you searched our list archives?
>>
>> http://archives.postgresql.org
>>
>>
>
>
>
I got it working somehow after I added a try and catch block and the
error you pointed out...
import java.sql.*;
class PostgreSQLTest{
public static void main(String[] args){
try{
Class.forName("org.postgresql.Driver");
String url="jdbc:postgresql://127.0.0.1/javatest";
Connection db = DriverManager.getConnection(url, "danish",
"postgresqljavatest");
//System.out.println("Connection Created");
Statement st = db.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM employee");
while (rs.next()) {
//System.out.print("Column 1 returned ");
System.out.println(rs.getString(1));
}
rs.close();
st.close();
db.close();}catch(Exception e){
System.out.println(e);}
}
}
Thanks
Danish
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2006-12-29 09:15 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-12-29 07:15 Error while trying to connect to postgresql Danish Siddiqui <dsiddiqui@vertex.co.in>
2006-12-29 09:07 ` Xavier Poinsard <xpoinsard@free.fr>
2006-12-29 09:15 ` Danish Siddiqui <dsiddiqui@vertex.co.in>
2006-12-29 09:15 ` Xavier Poinsard <xpoinsard@free.fr>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox