Inserindo e removendo uma coluna no banco de dados
Aprenda como adicionar e remover colunas no seu banco de dados utilizando Java.
Inserindo e removendo uma coluna no banco de dados
Inserindo a coluna:
try {
Statement stmt = connection.createStatement();
// Prepare a statement to insert a record
String sql = "INSERT INTO minha_tabela (col_string) VALUES('a string')";
// Execute the insert statement
stmt.executeUpdate(sql);
} catch (SQLException e) {
}Removendo a coluna:
try {
// Create a statement
Statement stmt = connection.createStatement();
// Prepare a statement to insert a record
String sql = "DELETE FROM minha_tabela WHERE col_string='a string'";
// Execute the delete statement
int deleteCount = stmt.executeUpdate(sql);
// deleteCount contains the number of deleted rows
// Use a prepared statement to delete
// Prepare a statement to delete a record
sql = "DELETE FROM minha_tabela WHERE col_string=?";
PreparedStatement pstmt = connection.prepareStatement(sql);
// Set the value
pstmt.setString(1, "a string");
deleteCount = pstmt.executeUpdate();
System.err.println(e.getMessage());
} catch (SQLException e) {
}
Artigos relacionados
-
Artigo
-
Artigo
-
Artigo
-
Artigo
-
Artigo