Java DataSource sqlExe(DataSource dataSource, String sql)

Here you can find the source of sqlExe(DataSource dataSource, String sql)

Description

sql Exe

License

Apache License

Declaration

public static void sqlExe(DataSource dataSource, String sql) 

Method Source Code


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

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

import javax.sql.DataSource;

public class Main {
    public static void sqlExe(DataSource dataSource, String sql) {
        Connection conn = null;/*from  w  ww .ja  v a2 s  .co m*/
        Statement stmt = null;
        try {
            conn = dataSource.getConnection();
            conn.setAutoCommit(false);
            stmt = conn.createStatement();
            stmt.execute(sql);
            conn.commit();
        } catch (Exception e) {
            if (conn != null) {
                try {
                    conn.rollback();
                } catch (SQLException e1) {
                    // ignore
                }
            }
            e.printStackTrace();
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                    // ignore
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    // ignore
                }
            }
        }
    }
}

Related

  1. myDataSource(String username, String password)
  2. purgeTables(DataSource ds)
  3. registerSpringDataSource(String name, DataSource dataSource)
  4. selectCount(DataSource ds, String tableName)
  5. setUpJndiDatasource()
  6. tableRecommendationExistsHsqdb(DataSource dataSource)
  7. update(DataSource dataSource, String sql, Object params[])
  8. update_Db(DataSource ds, String query)
  9. waitUntilDatabaseIsAvailable(DataSource dataSource, int timeoutSeconds)