GetString of Composite Type Postgres?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



GetString of Composite Type Postgres?



I created this table:


CREATE TABLE public.luogo
(
id_luogo integer NOT NULL DEFAULT nextval('luogo_id_luogo_seq'::regclass),
tipo character varying(30) NOT NULL,
indirizzo indirizzo,
CONSTRAINT luogo_pk PRIMARY KEY (id_luogo)
)



where indirizzo type is


CREATE TYPE public.indirizzo AS
(
citta character varying(50),
via character varying(50),
cap integer,
civico integer
);



So I'm using JDBC and I need this query


"SELECT * FROM luogo WHERE id_luogo= '"+variable+"'";



The problem is that resultset.getstring("indirizzo") returns obviously a string like: "(value,value,value)". How to get as string the singular parameters of indirizzo?


resultset.getstring("indirizzo")





String concatenation in a query string is vulnerable to SQL injection, you should use a prepared statement with parameters instead.
– Mark Rotteveel
Aug 10 at 16:01




1 Answer
1



The correct SQL syntax is:


"SELECT id_luogo,(indirizzo).citta FROM luogo"



To get the String in Java is: resultset.getString("citta")






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS