Skip site navigation (1) Skip section navigation (2)

simple insert operation

From: Aydın Toprak <aydin(dot)toprak(at)intengo(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: simple insert operation
Date: 2005-09-08 07:58:53
Message-ID: 431FEF3D.6050906@intengo.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
Hii guys,

I am very newbie about postgresql and I am making practice,
however I couldnt been able to insert a simple item to my DB via jdbc...


here is my code  for insertion...

        Class.forName("org.postgresql.Driver");
        String connectionStr = "jdbc:postgresql://localhost:5432/XXXX";
        Connection connection = 
java.sql.DriverManager.getConnection(connectionStr, "XXXX", "XXXX");
        String sqlQuery = "INSERT INTO passTable (idCol , pass) VALUES 
(3, 5)";
        PreparedStatement query = connection.prepareStatement(sqlQuery);
        query.executeUpdate();
        connection.close();

but I cant compile it

the errors

-------------------------------------------------------------------------------------------
form.java:26: unreported exception java.lang.ClassNotFoundException; 
must be cau
ght or declared to be thrown
                Class.forName("org.postgresql.Driver");
                             ^
form.java:28: unreported exception java.sql.SQLException; must be caught 
or decl
ared to be thrown
                Connection connection = 
java.sql.DriverManager.getConnection(con
nectionStr, "XXXX", "XXXX");
                                                                            
^
form.java:30: unreported exception java.sql.SQLException; must be caught 
or decl
ared to be thrown
                PreparedStatement query = 
connection.prepareStatement(sqlQuery);

                                                                     ^
form.java:31: unreported exception java.sql.SQLException; must be caught 
or decl
ared to be thrown
                query.executeUpdate();
                                   ^
form.java:32: unreported exception java.sql.SQLException; must be caught 
or decl
ared to be thrown
                connection.close();
                                ^
5 errors
-------------------------------------------------------------------------------------------

what is the problem I am stuck with it..





Responses

pgsql-jdbc by date

Next:From: Csaba NagyDate: 2005-09-08 08:17:26
Subject: Re: simple insert operation
Previous:From: Angelo NeuschitzerDate: 2005-09-07 16:52:51
Subject: BUG #1864: Strange behavoir of batches

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group