List of utility methods to do SQL Execute
List
| executeImmediate(String sql) execute Immediate List<List<String>> results = new ArrayList<List<String>>(); Connection conn = null; Statement statement = null; try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "gary", "12345"); conn.setAutoCommit(false); statement = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ... |
long | executeInsert(Connection conn, String sql, boolean hasAutoGeneratedKey, Object... parameters) execute Insert PreparedStatement stmt = null; ResultSet generatedKeysResultSet = null; long result = -1; try { if (hasAutoGeneratedKey) { stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); } else { stmt = conn.prepareStatement(sql); ... |
void | executeInsert(Connection conn, String targetTable, String destinationTable) execute Insert System.out.println("Attempting bulk insert using st_pointFromWKB"); PreparedStatement p_stmt = null; int count = 0; String query = "INSERT INTO " + destinationTable + " (objectid, shape) VALUES (?, sde.st_pointFromWKB(?, 2230))"; Map<Integer, byte[]> results = getShapeText(conn, targetTable); try { conn.setAutoCommit(true); ... |
int | executeInsertSQL(String sql) execute Insert SQL int b; System.out.println(sql + ";"); b = stmt.executeUpdate(sql); return b; |
void | executeQueries(Connection conn, InputStream stream) execute Queries BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8"))); StringBuffer buf = new StringBuffer(); String line; while ((line = reader.readLine()) != null) { buf.append(line.trim()); String[] queries = buf.toString().split(";"); Statement stmt = conn.createStatement(); ... |
void | executeResource(Connection con, String resource) execute Resource InputStream ins = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource); byte[] b = new byte[ins.available()]; ins.read(b); con.createStatement().execute(new String(b)); |
void | executeSetArgs(PreparedStatement stmt, Object... args) execute Set Args for (int i = 0; i < args.length; ++i) { stmt.setObject(i + 1, args[i]); int n = stmt.getParameterMetaData().getParameterCount(); for (int i = args.length; i < n; ++i) { stmt.setObject(i + 1, null); |
void | executeShutDownForHSQL(java.sql.Connection connection) execute ShutDown For HSQL connection. Statement statement = connection.createStatement();
statement.executeUpdate("SHUTDOWN;");
statement.close();
|
int | executeSP(Connection conn, String spName, Object... parameters) execute SP CallableStatement stmt = null; int result = -1; try { String sql = getCallStatementSQL(spName, parameters.length); stmt = conn.prepareCall(sql); bindParams(stmt, parameters); result = stmt.executeUpdate(); } finally { ... |
boolean | executeSql(Connection conn, String sql) execute Sql Statement stmt = null; try { stmt = conn.createStatement(); return stmt.execute(sql); } catch (Exception e) { throw e; } finally { if (stmt != null) { ... |