On 04/16/13 01:46 PM, Alejandro Rodríguez González wrote:
Basically, I insert using this code:
public void insertInputs(Set<Input> ri) throws Exception {
PreparedStatement psInsert = null;
Iterator<Input> it = ri.iterator();
while (it.hasNext()) {
Input in = it.next();
Note that doing it this way defeats the purpose of using prepared
statements, since you create and prepare it each time through the loop.
A better (faster) way would be to move the call to prepareStatement out
of the loop. But it does
psInsert = conn
.prepareStatement("insert into
inputs(input_class,api) values (?, ?)");
Where does conn come from here? Are you sure it is in autocommit mode?
It needs to be since you don't call conn.commit() explicitly. Also,
you're using the default schema for your table. Are you sure it is what
you believe it to be?
psInsert.setString(1, in.getObject());
If Constants.APIS[this.api] does not change as you iterate, it does not
need to be a parameter.
psInsert.setString(2, Constants.APIS[this.api]);
this.logger.log("Inserting input in db: " +
in.getObject() + " - API[" + Constants.APIS[this.api] + "]");
I assume that you see this output when you run your program?
psInsert.executeUpdate();
Place the close after the loop to re-use the prepared statement.
psInsert.close();
}
}
It is supposed that in the following execution of my program, when I
made the select statement to see the inputs in the database, it should
give me results, but.. no results are provided. I attach you the first
two executions of my program:
First (database not created): http://pastebin.com/1k7R8Yup
Second (database created. It is supposed that inputs table should
contain data): http://pastebin.com/yzsK1q9w
So.. as far as I understand, something is wrong in the "insert" but.. I
don't know what.
I hope someone can help me.
Thanks!
--
Dr. Alejandro Rodríguez González - PhD
Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA
Polytechnic University of Madrid
http://www.alejandrorg.com <http://www.alejandrorg.com/>
Phone: +34 914524900 . Ext: 25550
//Once the game is over, the king and the pawn go back in the same box.
- Italian proverb//