Search
 
SCRIPT & CODE EXAMPLE
 

SQL

prepared statement mysql java delete selected rows

package com.mkyong.jdbc.preparestatement.row;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class RowDelete {

    private static final String SQL_DELETE = "DELETE FROM EMPLOYEE WHERE NAME=?";

    public static void main(String[] args) {

        try (Connection conn = DriverManager.getConnection(
                "jdbc:postgresql://127.0.0.1:5432/test", "postgres", "password");
             PreparedStatement preparedStatement = conn.prepareStatement(SQL_DELETE)) {

            preparedStatement.setString(1, "mkyong");

            int row = preparedStatement.executeUpdate();

            // rows affected
            System.out.println(row);

        } catch (SQLException e) {
            System.err.format("SQL State: %s
%s", e.getSQLState(), e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
Comment

PREVIOUS NEXT
Code Example
Sql :: veri girme SQL 
Sql :: prestashop alter table if not exists 
Sql :: convert db timestamp to date 
Sql :: cassandra query example 
Sql :: concatenate sqlites 3 
Sql :: code to move ietms from one table to another myswl 
Sql :: no customers ordered 
Sql :: MYSQL create new query tab 
Sql :: mysql collation for case sensitive 
Sql :: Character Limitation in sp_executesql sql server 
Sql :: Get top 1 row of each group 
Sql :: mysql reset wp_options 
Sql :: oracle apex run 404 
Sql :: how to input data as id in database sql c# 
Sql :: SQL Hello, [firstname] [lastname] 
Sql :: postgre regex exactly 1 characters 
Sql :: what is constraints in dbms 
Sql :: Fatal error: Uncaught mysqli_sql_exception: Unknown or incorrect time zone 
Sql :: delete hangfire retries list 
Sql :: convert sql query to linq online 
Sql :: null plus 1 in sql 
Sql :: how to select only id where is not in column mysql 
Sql :: simple plsql program run in oracle sql developer but got the error 
Sql :: dbms interview questions 
Sql :: create query in where clasue 
Sql :: How to select only the first rows for each unique value of a sql tablecolumn? 
Sql :: classement rang mysql 7 
Sql :: pastashoppen 
Sql :: localhost ERROR 2006 (HY000) at line 1163: MySQL server has gone away 
Sql :: mysql create schgema 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =