Advertisement
Guest User

Untitled

a guest
May 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1.         Connection myCon;
  2.         try{
  3.           Class.forName("com.mysql.jdbc.Driver").newInstance();
  4.           // Connect to an instance of mysql with the follow details:
  5.           // machine address: pc236nt.napier.ac.uk
  6.           // database       : gisq
  7.           // user name      : scott
  8.           // password       : tiger
  9.        
  10.           myCon = DriverManager.getConnection(
  11.                   "jdbc:mysql://localhost:3306/kundenverwaltung",
  12.                   "root","");
  13.  
  14.         }
  15.         catch (Exception sqlEx){
  16.           System.err.println(sqlEx);
  17.         }
  18.       }
  19.  
  20.     public void kundenAnzeigen(){
  21.         Statement myStmt;
  22.         try {
  23.           myStmt = myCon.createStatement();
  24.           ResultSet result = myStmt.executeQuery("SELECT * FROM kunde");
  25.           while (result.next()){
  26.             System.out.println(result.getString("name"));
  27.           }
  28.         } catch (SQLException e) {
  29.             // TODO Auto-generated catch block
  30.             e.printStackTrace();
  31.         }
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement