Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lucasdota/jdbc_delete_values

Exercício em Java para treinar como deletar valores no mySQL
https://github.com/lucasdota/jdbc_delete_values

Last synced: 2 days ago
JSON representation

Exercício em Java para treinar como deletar valores no mySQL

Awesome Lists containing this project

README

        

## Exercício em Java para treinar como deletar valores no mySQL
### Programa principal:
```java
package application;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import db.DB;
import db.DbIntegrityException;

public class Program {

public static void main(String[] args) {

Connection conn = null;
PreparedStatement st = null;

try {
conn = DB.getConnection();
st = conn.prepareStatement(
"DELETE FROM department "
+ "WHERE "
+ "Id = ?");

st.setInt(1, 5);

int rowsAffected = st.executeUpdate();

System.out.println("Done! Rows affected: " + rowsAffected);
} catch (SQLException e) {
throw new DbIntegrityException(e.getMessage());
} finally {
DB.closeStatement(st);
DB.closeConnection();
}

}

}

```