Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zad3;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Ins1_b {
- static public void main(String[] args) {
- new Ins1();
- }
- PreparedStatement stmt;
- Ins1_b() {
- Connection con = null;
- try {
- con = DriverManager.getConnection("jdbc:derby:Z:/DerbyDbs/Ksidb");
- } catch (Exception exc) {
- System.out.println(exc);
- System.exit(1);
- }
- // nazwy wydawców do wpisywania do tabeli
- String[] wyd = { "PWN", "PWE", "Czytelnik", "Amber", "HELION", "MIKOM" };
- // pierwszy numer wydawcy do wpisywania do tabeli: PWN ma numer 15, PWE ma 16, ...
- int beginKey = 15;
- int delCount = 0;
- try {
- // przygotowanie instrukcji prekompilowanej
- //DELETE FROM table_name WHERE condition;
- stmt = con.prepareStatement("DELETE FROM wydawca WHERE wydid = ?"); // usunięcie z tabeli WYDAWCA rekordu o podanej nazwie wydawcy z tablicy wyd lub o podanym numerze wydawcy zaczynającym się od beginKey
- for (int i=0; i < wyd.length; i++) {
- stmt.setInt(1, beginKey);
- stmt.executeUpdate();
- beginKey++;
- }
- con.close();
- } catch(SQLException exc) {
- exc.printStackTrace();
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement