Best code examples for Java 8 Statement class (java.sql.Statement)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Statement class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Java 8 Statement examples from Open Source projects
This code example shows how to use the following methods: close, executeQuery
        Statement st = null;
        ResultSet rs = null;
 
        try { 
            st = con.createStatement();
            rs = st.executeQuery(query);
            if (rs != null && rs.next())
                result = rs.getString(1);
        } catch (Throwable t) {
            fail("it's impossible to execute query:" + query);
            t.printStackTrace();
        } finally { 
            if (rs != null) {
                try { 
                    rs.close();
                } catch (SQLException ignore) {
                    // Ignore 
                } 
            } 
            if (st != null) {

8
CodeRank
This code example shows how to use the following methods: executeQuery, setQueryTimeout
    try 
    { 
      stmt = conn.createStatement();
      if (timeoutSeconds > 0)
      { 
        stmt.setQueryTimeout(timeoutSeconds);
      } 
      rs = stmt.executeQuery(query);
 
      if (rs.next())
      { 
        res = rs.getLong(1);
        // NULL result is interpreted as 0 with getLong() 
        if (rs.wasNull())
        { 
          res = defaultVal;
        } 
      } 
    } 
    catch (SQLException e)

8
CodeRank
This code example shows how to use the following methods: executeQuery
		conn.close();
	} 
 
	public ResultSet executeQuery(String sql) throws SQLException {
		Statement stat = conn.createStatement();
		ResultSet rs = stat.executeQuery(sql);
		return rs;
	} 
 
	public int executeUpdate(String sql) throws SQLException {
		Statement stat = conn.createStatement();
		int affected_num = stat.executeUpdate(sql);
 
		if (stat != null) {
			stat.close();
		} 
		return affected_num;
	} 
} 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: execute
 
    public static void fillSalesPeopleTable(Connection conn)
            throws SQLException { 
        Statement statement = conn.createStatement();
 
        statement.execute(DatabaseCreator.INSERT_SALESPEOPLE1);
        statement.execute(DatabaseCreator.INSERT_SALESPEOPLE2);
        statement.execute(DatabaseCreator.INSERT_SALESPEOPLE3);
        statement.execute(DatabaseCreator.INSERT_SALESPEOPLE4);
        statement.execute(DatabaseCreator.INSERT_SALESPEOPLE5);
        statement.execute(DatabaseCreator.INSERT_SALESPEOPLE6);
    } 
 
    public static void fillCustomersTable(Connection conn) throws SQLException {
        Statement statement = conn.createStatement();
 
        statement.execute(DatabaseCreator.INSERT_CUSTOMERS1);
        statement.execute(DatabaseCreator.INSERT_CUSTOMERS2);
        statement.execute(DatabaseCreator.INSERT_CUSTOMERS3);
        statement.execute(DatabaseCreator.INSERT_CUSTOMERS4);
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: executeUpdate, setInt, setString, close
    } 
 
    private void addFlag(Connection connection, int newFlagId, String description, int lookupId) throws SQLException {
        PreparedStatement statement = connection.prepareStatement("insert into account_state_flag("
                + "  flag_id,lookup_id,status_id,flag_description,retain_flag)" + "values(?,?,?,?,?)"); 
        statement.setInt(1, newFlagId);
        statement.setInt(2, lookupId);
        statement.setInt(3, STATUS_10);
        statement.setString(4, description);
        boolean retain = false;
        statement.setInt(5, retain ? 1 : 0);
        statement.executeUpdate();
        statement.close();
    } 
} 
Full Snippet Info
8
CodeRank
Related Java 8 Statement Questions & Answers:
See Code Examples for Java 8 Statement Methods: