Java SQL Query executeQuery(Connection connection)

Here you can find the source of executeQuery(Connection connection)

Description

execute Query

License

Open Source License

Declaration

public static void executeQuery(Connection connection) throws SQLException 

Method Source Code

//package com.java2s;
/*//from  w w  w.j a v  a2  s .  c  o  m
 * Copyright (c) 2005-2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 *   WSO2 Inc. licenses this file to you under the Apache License,
 *   Version 2.0 (the "License"); you may not use this file except
 *   in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */

import java.sql.*;

public class Main {
    public static void executeQuery(Connection connection) throws SQLException {

        String sql01 = "INSERT INTO Persons (P_Id,LastName,FirstName,Address,City) VALUES (1,'Hansen','Ola','Timoteivn,10','Sandnes')";
        String sql02 = "INSERT INTO Persons (P_Id,LastName,FirstName,Address,City) VALUES (2,'Svendson','Tove','Borgvn,23','Sandnes')";
        String sql03 = "INSERT INTO Persons (P_Id,LastName,FirstName,Address,City) VALUES (3,'Pettersen','Kari','Storgt,20','Stavanger')";

        String sql04 = "INSERT INTO Orders (O_Id,OrderNo,P_Id) VALUES (1,77895,3)";
        String sql05 = "INSERT INTO Orders (O_Id,OrderNo,P_Id) VALUES (2,44678,3)";
        String sql06 = "INSERT INTO Orders (O_Id,OrderNo,P_Id) VALUES (3,22456,2)";
        String sql07 = "INSERT INTO Orders (O_Id,OrderNo,P_Id) VALUES (4,24562,1)";

        Statement statement = null;
        statement = connection.createStatement();
        statement.execute(sql01);
        statement.execute(sql02);
        statement.execute(sql03);
        statement.execute(sql04);
        statement.execute(sql05);
        statement.execute(sql06);
        statement.execute(sql07);

        System.out.println("SQL query executed successfully.");
    }
}

Related

  1. executeDDL(String query, Connection connection)
  2. executeForResult(Connection conn, String query, String... args)
  3. ExecuteNoneQuerys(String cmdtext, Object[] parms)
  4. executeQuery(Connection c, String query)
  5. ExecuteQuery(Connection conn, PreparedStatement preparedStatement, PreparedStatement lockStatement, String tablename)
  6. executeQuery(Connection connection, String query)
  7. executeQuery(Connection dbConnection, String selectString)
  8. executeQuery(java.sql.Connection con, String select, Object pk)
  9. executeQuery(Statement state, String sql)