List of usage examples for java.sql Statement execute
boolean execute(String sql) throws SQLException;
From source file:jp.co.tis.gsp.tools.dba.mojo.ExecuteDdlMojo.java
private void executeSql(String sql) throws SQLException { if ("".equals(sql.trim())) { return;//from w w w. j a va 2s . c o m } Statement stmt = conn.createStatement(); try { getLog().debug("SQL: " + sql); totalStatements++; stmt.execute(sql); successfulStatements++; } catch (SQLException ex) { throw new SQLException(sql, ex); } finally { StatementUtil.close(stmt); } }
From source file:com.octo.captcha.engine.bufferedengine.buffer.DatabaseCaptchaBufferTest.java
public CaptchaBuffer getBuffer() { //just get initialize the database and create //get the datasource from spring conf this.datasource = (DataSource) (new XmlBeanFactory(new ClassPathResource("testDatabaseCaptchaBuffer.xml"))) .getBean("dataSource"); //drop and recreate the table Connection con = null;//from ww w . j av a2s . c om Statement ps = null; ResultSet rs = null; try { con = datasource.getConnection(); ps = con.createStatement(); try { ps.execute(CREATE); } catch (SQLException e) { } ps = con.createStatement(); ps.execute(EMPTY); } catch (SQLException e) { if (rs != null) { try { rs.close(); } catch (SQLException ex) { } throw new RuntimeException(e); } } finally { if (ps != null) { try { ps.close(); } catch (SQLException e) { } } if (con != null) { try { con.close(); } catch (SQLException e) { } } } DatabaseCaptchaBuffer buffer = new DatabaseCaptchaBuffer(datasource); return buffer; }
From source file:com.adito.jdbc.JDBCConnectionImpl.java
void execute(String sqlString) throws SQLException { Statement stmt = conn.createStatement(); try {// w w w. ja v a 2 s .com stmt.execute(sqlString); } finally { stmt.close(); } }
From source file:de.klemp.middleware.controller.Controller.java
/** * With this method the devices can log out. Their names will be deleted * from the tables.//from w ww . ja v a 2 s . c o m * * @param component * 1 or 2 * @param classes * name of the class of the device * @param name * name, the device had subscribed. */ @GET @Path("/abmelden/{component}/{classes}/{name}") public static synchronized String unsubscribe(@PathParam("component") int component, @PathParam("classes") String classes, @PathParam("name") String name) { createDBConnection(); String ok = "ok"; name.replaceAll("\"", "\\\""); try { if (component == 1) { Statement statement = conn.createStatement(); statement.execute("delete from\"" + classes + "\"where name='" + name + "');"); PreparedStatement st = conn .prepareStatement("delete from \"InputDevices\" where name=" + name + ";"); st.setString(1, classes); st.setString(2, name); st.execute(); if (st.getUpdateCount() != 1) { ok = "class or method not found"; } } if (component == 2) { PreparedStatement st = conn .prepareStatement("delete from \"OutputDevices\" where \"class\"=? and \"topic\"=?;"); st.setString(1, classes); st.setString(2, name); st.execute(); deviceActive.remove(classes + "," + name); if (st.getUpdateCount() != 1) { ok = "class or method not found"; } } } catch (SQLException e) { logger.error("SQL Exception", e); } closeDBConnection(); return ok; }
From source file:com.splout.db.common.SQLiteJDBCManager.java
/** * The contract of this function is to return a JSON-ized ArrayList of JSON Objects which in Java are represented as * Map<String, Object>. So, for a query with no results, an empty ArrayList is returned. *//* ww w . j a va 2s . c o m*/ public String query(String query, int maxResults) throws SQLException, JSONSerDeException { long start = System.currentTimeMillis(); Connection connection = connectionPool.getConnection(); // fetch a connection Statement stmt = null; ResultSet rs = null; try { stmt = connection.createStatement(); String result = null; if (stmt.execute(query)) { rs = stmt.getResultSet(); result = JSONSerDe.ser(convertResultSetToList(rs, maxResults)); } else { result = JSONSerDe.ser(new ArrayList<HashMap<String, Object>>()); } long end = System.currentTimeMillis(); log.info(Thread.currentThread().getName() + ": Query [" + query + "] handled in [" + (end - start) + "] ms."); return result; } finally { if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } connection.close(); } }
From source file:com.thoughtworks.go.server.database.H2Database.java
public void shutdown() throws SQLException { if (systemEnvironment.inDbDebugMode()) { LOG.info("Shutting down database server."); if (tcpServer == null) { return; }/* w ww. ja v a 2 s.c om*/ if (dataSource != null) { dataSource.close(); } dataSource = null; tcpServer.stop(); tcpServer = null; } else { Connection connection = createDataSource().getConnection(); Statement statement = connection.createStatement(); statement.execute("SHUTDOWN"); statement.close(); dataSource.close(); dataSource = null; } }
From source file:ActualizadorLocal.Clientes.ClienteNodos.java
public void borrarDatosTablaNodos() throws SQLException { Statement st = conexion.crearSt(); st.execute("Alter table nodo disable keys;"); st = conexion.crearSt();//from w ww .j av a 2 s. com //st.executeUpdate("Delete from nodo;"); }
From source file:kr.co.bitnine.octopus.schema.metamodel.OctopusMetaModelTest.java
@Test public void testAddDataSourceExists() throws Exception { Connection conn = getConnection("octopus", "bitnine"); Statement stmt = conn.createStatement(); exception.expect(SQLException.class); stmt.execute("ALTER SYSTEM ADD DATASOURCE \"" + datasourceName + "\" CONNECT TO '" + connectionString + "' USING '" + driverName + "'"); stmt.close();/*from w w w. ja va 2s. c om*/ conn.close(); }
From source file:com.github.brandtg.switchboard.TestMysqlLogServer.java
@Test public void testRotateBinlog() throws Exception { try (Connection conn = DriverManager.getConnection(jdbc, "root", "")) { // Write some rows, so we have binlog entries PreparedStatement pstmt = conn.prepareStatement("INSERT INTO simple VALUES(?, ?)"); for (int i = 0; i < 10; i++) { pstmt.setInt(1, i);// w w w . ja va 2 s. co m pstmt.setInt(2, i); pstmt.execute(); } // Rotate logs Statement stmt = conn.createStatement(); stmt.execute("FLUSH LOGS"); // Write more for (int i = 10; i < 20; i++) { pstmt.setInt(1, i); pstmt.setInt(2, i); pstmt.execute(); } } pollAndCheck(serverAddress, "/log/test/0?count=100", 20, 20); }
From source file:com.microsoft.sqlserver.jdbc.connection.PoolingTest.java
@Test public void testConnectionPoolConnFunctions() throws SQLException { String tableName = RandomUtil.getIdentifier("table"); tableName = DBTable.escapeIdentifier(tableName); String sql1 = "if exists (select * from dbo.sysobjects where name = '" + tableName + "' and type = 'U')\n" + "drop table " + tableName + "\n" + "create table " + tableName + "\n" + "(\n" + "wibble_id int primary key not null,\n" + "counter int null\n" + ");"; String sql2 = "if exists (select * from dbo.sysobjects where name = '" + tableName + "' and type = 'U')\n" + "drop table " + tableName + "\n"; SQLServerXADataSource ds = new SQLServerXADataSource(); ds.setURL(connectionString);//from w w w . jav a2 s. c o m PooledConnection pc = ds.getPooledConnection(); Connection con = pc.getConnection(); Statement statement = con.createStatement(); statement.execute(sql1); statement.execute(sql2); con.clearWarnings(); pc.close(); }