Search in sources :

Example 1 with Connection

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();
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) HashSet(java.util.HashSet)

Example 2 with Connection

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();
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 3 with Connection

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 + "'");
    }
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection)

Example 4 with Connection

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");
    }
}
Also used : Connection(java.sql.Connection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileInputStream(java.io.FileInputStream)

Example 5 with Connection

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();
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Connection (java.sql.Connection)16438 PreparedStatement (java.sql.PreparedStatement)7635 SQLException (java.sql.SQLException)7048 ResultSet (java.sql.ResultSet)6941 Test (org.junit.Test)4455 Statement (java.sql.Statement)4396 Properties (java.util.Properties)1813 ArrayList (java.util.ArrayList)1311 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)915 IOException (java.io.IOException)535 CallableStatement (java.sql.CallableStatement)524 DatabaseMetaData (java.sql.DatabaseMetaData)486 DataSource (javax.sql.DataSource)449 HashMap (java.util.HashMap)418 File (java.io.File)347 List (java.util.List)318 MessageEvent (org.cerberus.engine.entity.MessageEvent)304 Map (java.util.Map)296 BaseTest (org.apache.phoenix.query.BaseTest)257 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)253