Do the declare statements and insert all have to be done in one statement
execute()?
That is, what is the scope of variables I declare?
I see a variety of syntax examples, some for older versions?
I'm using pg 9.2.2, so what are the rules/syntax for declaring and using
variables?
Use case: I
Bob,
Can you provide a snippet of code so I can understand what you mean by
declare ?
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On Mon, Jan 28, 2013 at 7:11 AM, Bob Futrelle bob.futre...@gmail.comwrote:
Do the declare statements and insert all have to be done in one
Here's a small, but complete code example - Bob
package us.tsos.dbs.pg;
import java.sql.*;
/**
* This is an effort to get a computed value from a Java function
* (or data object) included properly in the VALUES entries.
* So, how can I declare an SQL variable and set its value to some Java
You have two options:
st.execute(insert into hello values ('bKey', +f1()+));
or
PreparedStatement st = db.prepareStatement(insert into hello values
('bKey', ?));
st.setInteger(1, f1());
where 1 is the first parameter, 2 is the second parameter, and so on.
Regards,
Edson Richter
Em
Bob,
Ok, have a look at PreparedStatement
Essentially the same
PreparedStatement pstmt= db.prepareStatement(insert into hello values ?)
pstmt.setInt(1,intVar)
pstmt.execute()
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On Mon, Jan 28, 2013 at 1:50 PM, Bob Futrelle
Thanks to Edson and Dave for lightning responses.
I'm confident that your answers will do the job.
I'll follow up on the advice AFTER I get my coffee ;-)
I'm really focused on the NLP content of my research,
but I need a DB infrastructure to do it right.
(Not a bunch of files as in ancient
I would recommend the reading of the excellent The Java Tutorial, that
has a very well explained section about JDBC:
http://docs.oracle.com/javase/tutorial/jdbc/index.html
and the chapter about PreparedStatements:
http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html
Regards,
I had read 'through' the JDBC material,
but now reading more deeply with more insight.
The API is useful too.
Anyhoo, PreparedStatement works like a charm, viz.,
PreparedStatement pstmt= db.prepareStatement(insert into hello values
('cKey', ?));
pstmt.setInt(1,intVar);
pstmt.execute();
This