use of java.sql.PreparedStatement in project hs4j by killme2008.
the class MysqlThread method run.
@Override
public void run() {
try {
this.barrier.await();
} catch (Exception e) {
// ignore
}
final String insertSQL = "insert into user values(?,?,?,?,?,?,?,?,?,?,?)";
for (int i = 0; i < this.repeats; i++) {
String postfix = this.index + "_" + i;
Connection conn = null;
try {
conn = this.dataSource.getConnection();
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(insertSQL);
// id
pstmt.setInt(1, 0);
pstmt.setString(2, "my_first_name_" + postfix);
pstmt.setString(3, "last_name_" + postfix);
pstmt.setString(4, "myduty_" + postfix);
String phone = String.valueOf(i);
pstmt.setString(5, phone);
pstmt.setString(6, phone);
pstmt.setString(7, phone);
pstmt.setString(8, phone);
pstmt.setString(9, "my_home_address_" + postfix);
pstmt.setString(10, "my_office_address_" + postfix);
pstmt.setString(11, this.remark);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (pstmt != null) {
try {
pstmt.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
try {
this.barrier.await();
} catch (Exception e) {
// ignore
}
}
use of java.sql.PreparedStatement in project hs4j by killme2008.
the class HandlerSocketBinaryDecodeUnitTest method readBytesJDBC.
private byte[] readBytesJDBC(String key) throws Exception {
Connection conn = getConnection();
PreparedStatement ps = conn.prepareStatement("select value from hs4jtest where id = ?");
try {
ps.setString(1, key);
ResultSet rs = ps.executeQuery();
assertTrue(rs.next());
byte[] bytes = rs.getBytes(1);
return bytes;
} finally {
ps.close();
conn.close();
}
}
use of java.sql.PreparedStatement in project hs4j by killme2008.
the class HandlerSocketBinaryDecodeUnitTest method dropTable.
private void dropTable(Connection conn) throws Exception {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement("drop table hs4jtest");
ps.execute();
} finally {
ps.close();
conn.close();
}
}
use of java.sql.PreparedStatement in project torodb by torodb.
the class AbstractReadInterface method getCollectionResultSets.
@Override
@SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a DocPartResult. It's iterated and closed in caller code")
public List<DocPartResult> getCollectionResultSets(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCollection, Collection<Integer> dids) throws SQLException {
ArrayList<DocPartResult> result = new ArrayList<>();
Connection connection = dsl.configuration().connectionProvider().acquire();
try {
Iterator<? extends MetaDocPart> metaDocPartIterator = metaCollection.streamContainedMetaDocParts().sorted(TableRefComparator.MetaDocPart.DESC).iterator();
while (metaDocPartIterator.hasNext()) {
MetaDocPart metaDocPart = metaDocPartIterator.next();
String statament = getDocPartStatament(metaDatabase, metaDocPart, dids);
PreparedStatement preparedStatement = connection.prepareStatement(statament);
result.add(new ResultSetDocPartResult(metaDataReadInterface, dataTypeProvider, errorHandler, metaDocPart, preparedStatement.executeQuery(), sqlHelper));
}
} finally {
dsl.configuration().connectionProvider().release(connection);
}
return result;
}
use of java.sql.PreparedStatement in project torodb by torodb.
the class AbstractReadInterface method getAllCollectionDids.
@Override
@SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a Cursor<Integer>. It's iterated and closed in caller code")
public Cursor<Integer> getAllCollectionDids(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCollection) throws SQLException {
MetaDocPart rootDocPart = metaCollection.getMetaDocPartByTableRef(tableRefFactory.createRoot());
if (rootDocPart == null) {
return new EmptyCursor<>();
}
String statement = getReadAllCollectionDidsStatement(metaDatabase.getIdentifier(), rootDocPart.getIdentifier());
Connection connection = dsl.configuration().connectionProvider().acquire();
try {
PreparedStatement preparedStatement = connection.prepareStatement(statement);
return new DefaultDidCursor(errorHandler, preparedStatement.executeQuery());
} finally {
dsl.configuration().connectionProvider().release(connection);
}
}
Aggregations