Example usage for java.sql Statement executeUpdate

List of usage examples for java.sql Statement executeUpdate

Introduction

In this page you can find the example usage for java.sql Statement executeUpdate.

Prototype

int executeUpdate(String sql) throws SQLException;

Source Link

Document

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");
    Statement st = con.createStatement();
    st.executeUpdate("CREATE DATABASE myDB");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");

    Statement st = con.createStatement();
    st.executeUpdate("ALTER TABLE mytable DROP col");
    System.out.println("Column is deleted successfully!");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");

    Statement st = con.createStatement();
    int n = st.executeUpdate("ALTER TABLE mytable DROP INDEX col");
    System.out.println("Query OK, " + n + " rows affected.");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");

    Statement st = con.createStatement();
    int n = st.executeUpdate("ALTER TABLE myTable CHANGE old_col  new_col int");
    System.out.println("Query OK, " + n + " rows affected");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String driverName = "com.mysql.jdbc.Driver";
    String userName = "root";
    String password = "root";

    Class.forName(driverName).newInstance();
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", userName,
            password);/* w w w  .ja va  2 s .  c  om*/

    Statement st = con.createStatement();
    st.executeUpdate("DROP TABLE Employee1");
    con.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");

    Statement st = con.createStatement();
    int n = st.executeUpdate("ALTER TABLE mytable ADD col int");
    System.out.println("Query OK, " + n + " rows affected");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");

    Statement st = con.createStatement();
    int n = st.executeUpdate("ALTER TABLE mytable ADD UNIQUE( colName)");
    System.out.println("Query OK, " + n + " rows affected.");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String driver = "com.mysql.jdbc.Driver";

    Class.forName(driver);//ww w .  j  a  va 2 s  . c om
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");

    Statement st = con.createStatement();
    int val = st.executeUpdate("INSERT employee VALUES(" + 13 + "," + "'Aman'" + ")");
    System.out.println("1 row affected");

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    System.out.println("Inserting values in  database table!");
    Connection con = null;/*from   w  ww  .  ja va 2 s . co  m*/
    String url = "jdbc:jtds:sqlserver://127.0.0.1:1433/Example";
    String username = "sa";
    String password = "";
    String driver = "net.sourceforge.jtds.jdbc.Driver";
    Class.forName(driver);
    con = DriverManager.getConnection(url, username, password);
    Statement st = con.createStatement();
    int val = st.executeUpdate("insert into dbo.Company " + "values('abc', 2)");
    System.out.println("1 row affected");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    conn.setAutoCommit(false);//from  www  . j  a va 2s.  c o  m
    Statement st = conn.createStatement();

    st.executeUpdate("create table survey (id int,myURL CHAR);");

    String str = conn.nativeSQL("insert into survey(id) values(02)");

    System.out.println(str);

    conn.commit();
    st.close();
    conn.close();
}