pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: howalt <howaltwil@web.de>
To: pgsql-jdbc@postgresql.org
Subject: How to implement a dynamic string into a sql statement?
Date: Tue, 26 Aug 2014 19:24:27 +0200
Message-ID: <53FCC2CB.6080507@web.de> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

Hello Mailinglist! :-)

I have some spatial datasets which are availabe in a opensource metadata 
catalog software GeoNetwork and in a PostGIS database. The problem is 
that the student who created the database used different IDs for the 
same datasets. So the IDs in the GeoNetwork differs from the IDs in the 
postGIS database. They only have the same name

So, if someone uploads a new dataset into GeoNetwork, the same dataset 
is uploaded into a postGis database too.

Now I want to add a ID column into the database to give the field the 
same ID like the ID in geonetwork. I think I can only do this with using 
the filename cause they are same in both cases.

Now I want to alter the table in eclipse with following code:

Connection con = null;
PreparedStatement ps = null;
final String sqlps = "ALTER TABLE ? ADD COLUMN ?";

String filen = filename.substring(0, filename.indexOf('.'));
                 try {
                     con = 
DriverManager.getConnection("jdbc:postgresql_postGIS://localhost:5433/testdb?user=postgres&password=test");
                     try {
                         ps = con.prepareStatement(sqlps);
                         ps.setString(1, filen);
                         ps.setString(2, "GN_ID");

                         ps.execute();

But this does not work cause I am getting the following 
Exception:org.postgresql.util.PSQLException: ERROR: syntax error at »$1« 
Position: 13

So, it seems that PSQL has problems with the ? in the prepared 
statement. Does anyone know a solution for this problem?

I also tried using normale statement, but this is giving me a findbug 
error that I try to pass a nonconstant string to an execute method on an 
sql statement. So I really dont know how to get rid of this problem

Thank you in advance for every help



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



view thread (5+ messages)  latest in thread

Message-ID: <53FCC2CB.6080507@web.de>
Permalink:  ../53FCC2CB.6080507@web.de/
Also on:    postgresql.org/message-id/53FCC2CB.6080507@web.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: howaltwil@web.de
  Subject: Re: How to implement a dynamic string into a sql statement?
  In-Reply-To: <53FCC2CB.6080507@web.de>
  References: <53FCC2CB.6080507@web.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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