Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. package zad3;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9. public class Ins1_b {
  10.  
  11.  
  12.       static public void main(String[] args) {
  13.         new Ins1();
  14.       }
  15.  
  16.       PreparedStatement  stmt;
  17.  
  18.     Ins1_b()  {
  19.        Connection con = null;
  20.        try {
  21.            con = DriverManager.getConnection("jdbc:derby:Z:/DerbyDbs/Ksidb");
  22.            
  23.        } catch (Exception exc)  {
  24.          System.out.println(exc);
  25.          System.exit(1);
  26.        }
  27.         // nazwy wydawców do wpisywania do tabeli
  28.        String[] wyd =  { "PWN", "PWE", "Czytelnik", "Amber", "HELION", "MIKOM" };
  29.  
  30.         // pierwszy numer wydawcy do wpisywania do tabeli: PWN ma numer 15, PWE ma 16, ...
  31.      int beginKey = 15;
  32.      int delCount =  0;
  33.                try  {
  34.                  // przygotowanie instrukcji prekompilowanej
  35.                    //DELETE FROM table_name  WHERE condition;
  36.                  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
  37.                  for (int i=0; i < wyd.length; i++)   {
  38.                    stmt.setInt(1, beginKey);
  39.                    stmt.executeUpdate();
  40.                    beginKey++;
  41.                  }
  42.                  con.close();
  43.                } catch(SQLException exc)  {
  44.                    exc.printStackTrace();
  45.                }
  46.  
  47.    
  48.    
  49.    
  50. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement