21.05.2014 Views

Android & PostgreSQL (application/pdf - 311.5 KB) - PGCon

Android & PostgreSQL (application/pdf - 311.5 KB) - PGCon

Android & PostgreSQL (application/pdf - 311.5 KB) - PGCon

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Execute a Query with a Bind Value<br />

Building on the previous slide, select the number of all relations from pg class:<br />

S t r i n g s q l = ”SELECT COUNT( ∗ ) FROM p g c l a s s WHERE r e l k i n d = ? ; ”<br />

PreparedStatement ps = conn . c r e a t e S t a t e m e n t ( ) ;<br />

// Bind v a r i a b l e s a r e enumerated s t a r t i n g with 1 ;<br />

ps . s e t S t r i n g ( 1 , ” r ” ) ;<br />

R e s u l t S e t r s = ps . executeQuery ( s q l ) ;<br />

r s . next ( ) ;<br />

Columns a r e enumerated s t a r t i n g with 1 .<br />

long count = r s . getLong ( 1 ) ;<br />

r s . c l o s e ( ) ;<br />

ps . c l o s e ( ) ;<br />

markwkm (<strong>PGCon</strong>2011) <strong>Android</strong> & <strong>PostgreSQL</strong> 20 May 2011 13 / 37

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!