Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class Austoben {
  4.  
  5. public static final String Select = "SELECT WKN, Name FROM Wertpapier WHERE TYP = 'AKTIE' ORDER BY NAME ";
  6.  
  7. //public static Connection conn = null;
  8.  
  9. public static void main(String[] args) throws SQLException {
  10.  
  11. new oracle.jdbc.OracleDriver();
  12. Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@orahost:1521:infdb", "gruberc2", "gruberc2");
  13.  
  14. Statement stmt = conn.createStatement();
  15.  
  16. int bLines = stmt.executeUpdate("DELETE FROM BRANCHE WHERE BID = 1");
  17. System.out.println("Gelöschte Zeilen: " + bLines);
  18.  
  19. int cLines = stmt.executeUpdate("INSERT INTO Branche(BID, Name) VALUES (1, 'Telekommunikation')");
  20. System.out.println("Hinzugefügte Zeilen: " + cLines);
  21.  
  22. //int nLines = stmt.executeUpdate("DELETE FROM Branche WHERE BID BETWEEN 13 AND 20");
  23. //System.out.println("GELÖSCHTE ZEILEN: " + nLines);
  24.  
  25. int dLines = stmt.executeUpdate("INSERT ALL INTO Branche(BID, Name) VALUES (15, 'Test 1')"
  26. + "INTO BRANCHE(BID, Name) VALUES(16, 'Test2')"
  27. + "INTO BRANCHE(BID, Name) VALUES(17, 'Test3')"
  28. + "SELECT * FROM DUAL");
  29.  
  30. System.out.println("Hinzugefügte Zeilen: " + dLines);
  31.  
  32. int aLines = stmt.executeUpdate("UPDATE Branche SET Name = 'Chris' WHERE BID = 1");
  33. System.out.println("Geänderte Zeilen: " + aLines);
  34.  
  35. //ResultSet rset1 = stmt.executeQuery("SELECT * FROM BRANCHE ORDER BY BID ASC");
  36. //System.out.println();
  37.  
  38. PreparedStatement pStmt = conn.prepareStatement(Select);
  39. ResultSet rset = pStmt.executeQuery();
  40. while(rset.next())
  41. System.out.println("WKN: " + rset.getInt("WKN") + " Name: " + rset.getString("Name"));
  42.  
  43.  
  44.  
  45. rset = stmt.executeQuery("SELECT * FROM BRANCHE ORDER BY BID ASC");
  46. while(rset.next())
  47. System.out.println("BID: " + rset.getInt("BID") + " BRANCHE: " + rset.getString("NAME") + "\n");
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement