Statement.close
Code IndexAdd Codota to your IDE (free)

Best code snippets using java.sql.Statement.close(Showing top 20 results out of 5,103)

Refine search

  • Connection.createStatement
  • ResultSet.close
  • ResultSet.next
  • Statement.executeQuery
  • Connection.close
  • ResultSet.getString
  • Common ways to obtain Statement
private void myMethod () {
Statement s =
  • Connection connection;connection.createStatement()
  • Connection connection;connection.createStatement(resultSetType, resultSetConcurrency)
  • Connection connection;connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability)
  • AI code suggestions by Codota
}
origin: ch.qos.logback/logback-classic

long getLastEventId() throws SQLException {
  DriverManagerConnectionSource cs = getConnectionSource();
  Connection con = cs.getConnection();
  Statement statement = con.createStatement();
  statement.setMaxRows(1);
  ResultSet rs = statement.executeQuery("select event_id from logging_event order by event_id desc");
  rs.next();
  long eventId = rs.getLong(1);
  rs.close();
  statement.close();
  return eventId;
}
origin: stackoverflow.com

 Statement stmt = conn.createStatement();
try {
  ResultSet rs = stmt.executeQuery( "SELECT FULL_NAME FROM EMP" );
  try {
    while ( rs.next() ) {
      System.out.println( "Name: " + rs.getString("FULL_NAME") );
    }
  } finally {
    try { rs.close(); } catch (Exception ignore) { }
  }
} finally {
  try { stmt.close(); } catch (Exception ignore) { }
}
origin: stackoverflow.com

 Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT ID FROM USERS");
...
rs.close();
stmt.close();
conn.close();
origin: ch.qos.logback/logback-classic

@Test
public void testAppendMultipleEvents() throws SQLException {
  for (int i = 0; i < 10; i++) {
    ILoggingEvent event = createLoggingEvent();
    appender.append(event);
  }
  Statement stmt = connectionSource.getConnection().createStatement();
  ResultSet rs = null;
  rs = stmt.executeQuery("SELECT * FROM logging_event");
  int count = 0;
  while (rs.next()) {
    count++;
  }
  assertEquals(10, count);
  rs.close();
  stmt.close();
}
origin: ch.qos.logback/logback-classic

private void executeQuery(Connection conn, String expression) throws SQLException {
  Statement st = null;
  st = conn.createStatement();
  int i = st.executeUpdate(expression);
  if (i == -1) {
    throw new IllegalStateException("db error : " + expression);
  }
  st.close();
}
origin: mysql/mysql-connector-java

public Xid[] recover(int flag) throws XAException {
  return recover(this.underlyingConnection, flag);
}
origin: ch.qos.logback/logback-classic

@Test
public void testAppendThrowable() throws SQLException {
  ILoggingEvent event = createLoggingEvent();
  appender.append(event);
  Statement stmt = connectionSource.getConnection().createStatement();
  ResultSet rs = null;
  rs = stmt.executeQuery("SELECT * FROM LOGGING_EVENT_EXCEPTION WHERE EVENT_ID=1");
  rs.next();
  String expected = "java.lang.Exception: test Ex";
  String firstLine = rs.getString(3);
  assertTrue("[" + firstLine + "] does not match [" + expected + "]", firstLine.contains(expected));
  int i = 0;
  while (rs.next()) {
    expected = event.getThrowableProxy().getStackTraceElementProxyArray()[i].toString();
    String st = rs.getString(3);
    assertTrue("[" + st + "] does not match [" + expected + "]", st.contains(expected));
    i++;
  }
  assertTrue(i != 0);
  rs.close();
  stmt.close();
}
origin: druid-io/druid

@Test
public void testNotTooManyConnectionsWhenTheyAreEmpty() throws Exception
{
 final Connection connection1 = DriverManager.getConnection(url);
 connection1.createStatement().close();
 final Connection connection2 = DriverManager.getConnection(url);
 connection2.createStatement().close();
 final Connection connection3 = DriverManager.getConnection(url);
 connection3.createStatement().close();
 final Connection connection4 = DriverManager.getConnection(url);
 Assert.assertTrue(true);
}
origin: ch.qos.logback/logback-classic

@Test
public void testAppendLoggingEvent() throws SQLException {
  ILoggingEvent event = createLoggingEvent();
  appender.append(event);
  StatusPrinter.print(loggerContext);
  Statement stmt = connectionSource.getConnection().createStatement();
  ResultSet rs = null;
  rs = stmt.executeQuery("SELECT * FROM logging_event");
  if (rs.next()) {
    assertEquals(event.getTimeStamp(), rs.getLong(DBAppender.TIMESTMP_INDEX));
    assertEquals(event.getFormattedMessage(), rs.getString(DBAppender.FORMATTED_MESSAGE_INDEX));
    assertEquals(event.getLoggerName(), rs.getString(DBAppender.LOGGER_NAME_INDEX));
    assertEquals(event.getLevel().toString(), rs.getString(DBAppender.LEVEL_STRING_INDEX));
    assertEquals(event.getThreadName(), rs.getString(DBAppender.THREAD_NAME_INDEX));
    assertEquals(DBHelper.computeReferenceMask(event), rs.getShort(DBAppender.REFERENCE_FLAG_INDEX));
    assertEquals(String.valueOf(diff), rs.getString(DBAppender.ARG0_INDEX));
    StackTraceElement callerData = event.getCallerData()[0];
    assertEquals(callerData.getFileName(), rs.getString(DBAppender.CALLER_FILENAME_INDEX));
    assertEquals(callerData.getClassName(), rs.getString(DBAppender.CALLER_CLASS_INDEX));
    assertEquals(callerData.getMethodName(), rs.getString(DBAppender.CALLER_METHOD_INDEX));
  } else {
    fail("No row was inserted in the database");
  }
  rs.close();
  stmt.close();
}
origin: apache/storm

private List<Object> testExpr(List<String> exprs) throws Exception {
  Class.forName("org.apache.calcite.jdbc.Driver");
  Connection connection =
      DriverManager.getConnection("jdbc:calcite:");
  CalciteConnection calciteConnection =
      connection.unwrap(CalciteConnection.class);
  SchemaPlus rootSchema = calciteConnection.getRootSchema();
  rootSchema.add("expr", new ReflectiveSchema(new ExprDatabase()));
  Statement statement = connection.createStatement();
  ResultSet resultSet =
      statement.executeQuery("select " + Joiner.on(',').join(exprs) + " \n"
          + "from \"expr\".\"expressions\" as s\n"
          + " WHERE s.\"id\" > 0 AND s.\"id\" < 2");
  List<Object> result = null;
  while (resultSet.next()) {
    if (result != null) {
      Assert.fail("The query is expected to have only one result row");
    }
    int n = resultSet.getMetaData().getColumnCount();
    result = new ArrayList<>();
    for (int i = 1 ; i <= n; i++) {
      result.add(resultSet.getObject(i));
    }
  }
  resultSet.close();
  statement.close();
  connection.close();
  return result;
}
origin: ch.qos.logback/logback-classic

@Test
public void testContextInfo() throws SQLException {
  loggerContext.putProperty("testKey1", "testValue1");
  MDC.put("k" + diff, "v" + diff);
  ILoggingEvent event = createLoggingEvent();
  appender.append(event);
  Statement stmt = connectionSource.getConnection().createStatement();
  ResultSet rs = null;
  rs = stmt.executeQuery("SELECT * FROM LOGGING_EVENT_PROPERTY WHERE EVENT_ID=1");
  Map<String, String> map = appender.mergePropertyMaps(event);
  int i = 0;
  while (rs.next()) {
    String key = rs.getString(2);
    assertEquals(map.get(key), rs.getString(3));
    i++;
  }
  assertTrue(map.size() != 0);
  assertEquals(map.size(), i);
  rs.close();
  stmt.close();
}
origin: stackoverflow.com

 public insertUser(String name, String email) {
  Connection conn = null;
  PreparedStatement stmt = null;
  try {
   conn = setupTheDatabaseConnectionSomehow();
   stmt = conn.prepareStatement("INSERT INTO person (name, email) values (?, ?)");
   stmt.setString(1, name);
   stmt.setString(2, email);
   stmt.executeUpdate();
  }
  finally {
   try {
     if (stmt != null) { stmt.close(); }
   }
   catch (Exception e) {
     // log this error
   }
   try {
     if (conn != null) { conn.close(); }
   }
   catch (Exception e) {
     // log this error
   }
  }
}
origin: stackoverflow.com

 Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;

try {
  // Do stuff
  ...

} catch (SQLException ex) {
  // Exception handling stuff
  ...
} finally {
  if (rs != null) {
    try {
      rs.close();
    } catch (SQLException e) { /* ignored */}
  }
  if (ps != null) {
    try {
      ps.close();
    } catch (SQLException e) { /* ignored */}
  }
  if (conn != null) {
    try {
      conn.close();
    } catch (SQLException e) { /* ignored */}
  }
}
origin: MyCATApache/Mycat-Server

private long insert(Connection con, List<String> list) throws SQLException {
  Statement stms = con.createStatement();
  for (String sql : list) {
    stms.addBatch(sql);
  }
  stms.executeBatch();
  if (this.autocommit == false) {
    con.commit();
  }
  // stms.clearBatch();
  stms.close();
  return list.size();
}
origin: MyCATApache/Mycat-Server

private static void testMultiNodeLargeResultset(Connection theCon)
    throws SQLException {
  theCon.setAutoCommit(true);
  System.out.println("testMultiNodeLargeResultset begin");
  String sql = "select * from travelrecord  limit 100000";
  for (int i = 0; i < 100; i++) {
    Statement stmt = theCon.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
    int count = 0;
    while (rs.next()) {
      count++;
    }
    rs.close();
    stmt.close();
    System.out.println("total result " + count);
  }
  System.out.println("testMultiNodeLargeResultset end");
}
origin: MyCATApache/Mycat-Server

@Override
public boolean testConnection(String schema) throws IOException {
  boolean isConnected = false;	
  
  Connection connection = null;
  Statement statement = null;
  try {
    DBHostConfig cfg = getConfig();
    connection = DriverManager.getConnection(cfg.getUrl(), cfg.getUser(), cfg.getPassword());
    statement = connection.createStatement();			
    if (connection != null && statement != null) {
      isConnected = true;
    }            
  } catch (SQLException e) {
    e.printStackTrace();
  } finally {			
    if (statement != null) {
      try { statement.close(); } catch (SQLException e) {}
    }
    
    if (connection != null) {
      try { connection.close(); } catch (SQLException e) {}
    }
  }        
  return isConnected;
}
origin: mysql/mysql-connector-java

results = stmt.executeQuery("SHOW DATABASES");
while (results.next()) {
  resultsAsList.add(results.getString(1));
if (results != null) {
  try {
    results.close();
  } catch (SQLException sqlEx) {
    AssertionFailedException.shouldNotHappen(sqlEx);
    stmt.close();
  } catch (SQLException sqlEx) {
    AssertionFailedException.shouldNotHappen(sqlEx);
origin: mysql/mysql-connector-java

      "Connection id %d not found in \"SHOW PROCESSLIST\", assuming 32-bit overflow, using SELECT CONNECTION_ID() instead", threadId));
  ResultSet rs = processListStmt.executeQuery("SELECT CONNECTION_ID()");
  if (rs.next()) {
    threadId = rs.getLong(1);
    processHost = findProcessHost(threadId, processListStmt);
processListStmt.close();
origin: com.h2database/h2

@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
  try {
    Statement stat = conn.createStatement();
    stat.execute("SHUTDOWN");
    stat.close();
  } catch (Exception e) {
    e.printStackTrace();
  }
  try {
    conn.close();
  } catch (Exception e) {
    e.printStackTrace();
  }
  if (server != null) {
    server.stop();
    server = null;
  }
}
origin: org.hibernate/hibernate-core

@Override
public Iterable<SequenceInformation> extractMetadata(ExtractionContext extractionContext) throws SQLException {
  final IdentifierHelper identifierHelper = extractionContext.getJdbcEnvironment().getIdentifierHelper();
  final Statement statement = extractionContext.getJdbcConnection().createStatement();
  try {
    ResultSet resultSet = statement.executeQuery(
        "select SEQUENCE_CATALOG, SEQUENCE_SCHEMA, SEQUENCE_NAME, INCREMENT " +
            "from information_schema.sequences"
    try {
      final List<SequenceInformation> sequenceInformationList = new ArrayList<SequenceInformation>();
      while ( resultSet.next() ) {
        sequenceInformationList.add(
            new SequenceInformationImpl(
                new QualifiedSequenceName(
                    identifierHelper.toIdentifier(
                        resultSet.getString( "SEQUENCE_CATALOG" )
                    ),
                    identifierHelper.toIdentifier(
                        resultSet.getString( "SEQUENCE_SCHEMA" )
                    ),
                    identifierHelper.toIdentifier(
                        resultSet.getString( "SEQUENCE_NAME" )
        resultSet.close();
      statement.close();
java.sqlStatementclose

Javadoc

Releases this Statement object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. It is generally good practice to release resources as soon as you are finished with them to avoid tying up database resources.

Calling the method close on a Statement object that is already closed has no effect.

Note:When a Statement object is closed, its current ResultSet object, if one exists, is also closed.

Popular methods of Statement

  • executeQuery
    Executes a supplied SQL statement. Returns a single ResultSet.
  • execute
    Executes the supplied SQL statement. This may return multiple ResultSets. This method allows retriev
  • executeUpdate
    Executes the supplied SQL statement. This method allows retrieval of auto generated keys specified b
  • getResultSet
    Gets the current result. Should only be called once per result.
  • setFetchSize
    Sets the fetch size. This is a hint to the JDBC driver about how many rows should be fetched from th
  • getUpdateCount
    Gets an update count for the current result if it is not a ResultSet.
  • executeBatch
    Submits a batch of SQL commands to the database. Returns an array of update counts, if all the comma
  • setQueryTimeout
    Sets the timeout, in seconds, for queries - how long the driver will allow for completion of a state
  • addBatch
    Adds a specified SQL command to the list of commands for this Statement. The list of commands is exe
  • setMaxRows
    Sets the maximum number of rows that any ResultSet can contain. If the number of rows exceeds this v
  • getGeneratedKeys
    Returns auto generated keys created by executing this statement.
  • getWarnings
    Retrieves the first SQLWarning reported by calls on this statement. If there are multiple warnings,
  • getGeneratedKeys,
  • getWarnings,
  • getConnection,
  • getMoreResults,
  • cancel,
  • isClosed,
  • clearWarnings,
  • getMaxRows,
  • setEscapeProcessing

Popular classes and methods

  • requestLocationUpdates (LocationManager)
  • getSharedPreferences (Context)
  • getExternalFilesDir (Context)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java virtua
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • MalformedURLException (java.net)
    Thrown to indicate that a malformed URL has occurred. Either no legal protocol could be found in a s
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Iterator (java.util)
    An iterator over a collection. Iterator takes the place of Enumeration in the Java Collections Frame
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if

For IntelliJ IDEA and
Android Studio

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)