use of java.sql.Connection in project jetty.project by eclipse.
the class JdbcTestHelper method getSessionIds.
public static Set<String> getSessionIds() throws Exception {
HashSet<String> ids = new HashSet<String>();
Class.forName(DRIVER_CLASS);
Connection con = null;
try {
con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);
PreparedStatement statement = con.prepareStatement("select " + ID_COL + " from " + TABLE);
ResultSet result = statement.executeQuery();
while (result.next()) {
ids.add(result.getString(1));
}
return ids;
} finally {
if (con != null)
con.close();
}
}
use of java.sql.Connection in project jetty.project by eclipse.
the class JdbcTestHelper method existsInSessionTable.
public static boolean existsInSessionTable(String id, boolean verbose) throws Exception {
Class.forName(DRIVER_CLASS);
Connection con = null;
try {
con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);
PreparedStatement statement = con.prepareStatement("select * from " + TABLE + " where " + ID_COL + " = ?");
statement.setString(1, id);
ResultSet result = statement.executeQuery();
if (verbose) {
boolean results = false;
while (result.next()) {
results = true;
}
return results;
} else
return result.next();
} finally {
if (con != null)
con.close();
}
}
use of java.sql.Connection in project jetty.project by eclipse.
the class DataSourceLoginServiceTest method changePassword.
protected void changePassword(String user, String newpwd) throws Exception {
Loader.loadClass("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
try (Connection connection = DriverManager.getConnection(DatabaseLoginServiceTestServer.__dbURL, "", "");
Statement stmt = connection.createStatement()) {
connection.setAutoCommit(true);
stmt.executeUpdate("update users set pwd='" + newpwd + "' where username='" + user + "'");
}
}
use of java.sql.Connection in project jetty.project by eclipse.
the class DatabaseLoginServiceTestServer method runscript.
public static int runscript(File scriptFile) throws Exception {
//System.err.println("Running script:"+scriptFile.getAbsolutePath());
try (FileInputStream fileStream = new FileInputStream(scriptFile)) {
Loader.loadClass("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
Connection connection = DriverManager.getConnection(__dbURL, "", "");
ByteArrayOutputStream out = new ByteArrayOutputStream();
return ij.runScript(connection, fileStream, "UTF-8", out, "UTF-8");
}
}
use of java.sql.Connection in project sharding-jdbc by dangdangdotcom.
the class AbstractShardingBothDataBasesAndTablesSpringDBUnitTest method selectData.
private void selectData() throws SQLException {
String sql = "SELECT i.order_id, i.order_item_id FROM `t_order` o JOIN `t_order_item` i ON o.user_id = i.user_id AND o.order_id = i.order_id" + " WHERE o.`user_id` = ? AND o.`order_id` = ? AND i.`order_id` = ? ORDER BY i.order_item_id DESC";
try (Connection connection = getShardingDataSource().getConnection()) {
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, 1);
preparedStatement.setInt(2, 1);
preparedStatement.setInt(3, 1);
ResultSet resultSet = preparedStatement.executeQuery();
int count = 0;
while (resultSet.next()) {
if (0 == count) {
assertThat(resultSet.getInt(1), is(1));
assertThat(resultSet.getInt(2), is(5));
} else if (1 == count) {
assertThat(resultSet.getInt(1), is(1));
assertThat(resultSet.getInt(2), is(1));
}
count++;
}
preparedStatement.close();
}
}
Aggregations