Java SQL Execute executeStatement(final String databaseName, final String statement)

Here you can find the source of executeStatement(final String databaseName, final String statement)

Description

execute Statement

License

Apache License

Declaration

public static void executeStatement(final String databaseName, final String statement) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.Connection;
import java.sql.DriverManager;

import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    private final static StringBuilder sb = new StringBuilder();
    private static final String JDBC_PREFIX = "jdbc:sqlite:";
    private static final String DB_SUFFIX = ".db";

    public static void executeStatement(final String databaseName, final String statement) {
        Connection c = null;// ww  w  . j  av a  2s.  c  om
        Statement stmt = null;
        try {
            c = DriverManager.getConnection("jdbc:sqlite:" + databaseName + ".db");
            stmt = c.createStatement();
            stmt.executeUpdate(statement);
            stmt.close();
            c.close();
        } catch (Exception e) {
            System.err.println(e.getClass().getName() + ": " + e.getMessage());
        }
    }

    public static Connection getConnection(final String databaseName) throws SQLException {
        sb.setLength(0);
        sb.append(JDBC_PREFIX).append(databaseName).append(DB_SUFFIX);
        Connection conn = null;
        conn = DriverManager.getConnection(sb.toString());
        sb.setLength(0);
        return conn;
    }
}

Related

  1. executeSqlFile(Connection connection, String sqlPath)
  2. executeSqlFile(String filename, Connection connection)
  3. executeSqlFromSql(Connection connection, String sql, String name)
  4. executeStatement(Connection con, String sql)
  5. executeStatement(Connection conn, String command)
  6. executeStatements(final Connection conn, final List statements)
  7. executeUnRegister(String schemaName, String tableName, String columnName, Connection con)