Software

Java: sfruttarlo al meglio con le prepared statements

Michele Costabile | 27 Giugno 2017

Un esempio di classe derivata import java.sql.Connection; import java.sql.SQLException; import java.util.Arrays; public class PersonAdder extends AbstractAdder { public PersonAdder(Connection connection) […]

Un esempio di classe derivata

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Arrays;

public class PersonAdder extends AbstractAdder {
public PersonAdder(Connection connection) {
super(connection);
this.tableName = “person”;
this.fields = Arrays.asList(“id”, “name”);
}

@Override
public void update() throws SQLException {
try {
pstmt.setInt(fieldNo(“id”), 10);
pstmt.setString(fieldNo(“name”), “Bob”);
} catch (IllegalArgumentException e)
{
logger.severe(e.getMessage());
e.printStackTrace();
}

pstmt.addBatch();

// Run transaction
int[] result = pstmt.executeBatch();
if (pstmt != null)
pstmt.close();
}
}

< Indietro Successivo >