Java DataSource update_Db(DataSource ds, String query)

Here you can find the source of update_Db(DataSource ds, String query)

Description

updat Db

License

Open Source License

Declaration

static public int update_Db(DataSource ds, String query) throws SQLException 

Method Source Code

//package com.java2s;
/*/*from   w  w w. j av  a  2s.  c  om*/
 * Copyright (c) 2014-2015 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 */

import java.sql.Connection;

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

import javax.sql.DataSource;

public class Main {
    static public int update_Db(DataSource ds, String query) throws SQLException {

        //
        // Run the query
        //
        Connection conn = null;
        Statement stmt = null;
        int updated = 0;

        try {
            conn = ds.getConnection();
            stmt = conn.createStatement();
            updated = stmt.executeUpdate(query);

        } catch (SQLException e) {
            throw e;
        } finally {
            try {
                if (stmt != null)
                    stmt.close();
                if (conn != null)
                    conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        return updated;
    }
}

Related

  1. selectCount(DataSource ds, String tableName)
  2. setUpJndiDatasource()
  3. sqlExe(DataSource dataSource, String sql)
  4. tableRecommendationExistsHsqdb(DataSource dataSource)
  5. update(DataSource dataSource, String sql, Object params[])
  6. waitUntilDatabaseIsAvailable(DataSource dataSource, int timeoutSeconds)