Advertisement
Guest User

Untitled

a guest
May 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import java.sql.*;
  2. public class InventarDB {
  3.  
  4. public static void main(String[] args) {
  5. Connection con = null;
  6. try {
  7. Class.forName("com.mysql.jdbc.Driver");
  8. System.out.println("Treiber loaded .... yey");
  9. }
  10. catch(ClassNotFoundException cnfe) {
  11. System.out.println("Treiberklasse nicht gefunden!");
  12. System.exit(1);
  13. }
  14. try {
  15. con = DriverManager.getConnection("jdbc:mysql://localhost/inventar", "matthias", "test123");
  16. System.out.println("Verbindung hergestellt.");
  17. }
  18. catch(SQLException se) {
  19. System.out.println("Verbindung konnte nicht hergestellt werden.");
  20. }
  21. Statement stmt = null;
  22. try {
  23. stmt = con.createStatement();
  24. System.out.println("Statement ok");
  25. }
  26. catch(SQLException se)
  27. {
  28. System.out.println("Abfrage nicht möglich");
  29. }
  30. String abfrage = "select * from personal";
  31. ResultSet rs = null;
  32. try {
  33. rs = stmt.executeQuery(abfrage);
  34. System.out.println("Execute OK");
  35. }
  36. catch(SQLException se)
  37. {
  38. System.out.println("Abfrage nicht erfolgt");
  39. }
  40. rs.next();
  41. System.out.println("1. Zeile." + rs.getInt(1) + " " + rs.getString(2) + rs.getString(3));
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement