This flashcard is just one of a free flashcard set. See all flashcards!
34
JDBC Ablauf Abfrage
C(onnection), S(tatement), R(esultSet)
0. Parameter Definieren:
String ConnectionURL ="jdbc:mysql://localhost:3306/dhbw";
String user = "root";
String pw="";
String query1 ="SELECT * FROM Student";
1. Connection
Connection con = null;
con = DriverManager.getConnection(ConnectionURL,user,pw);
2. Statement erstellen
Statement stmt1 = con.createStatement();
3. Statement ausführen
ResultSet rset1 = stmt1.executeQuery(query1);
bzw.
executeQuery (SELECT)
executeUpdate (DELETE, INSERT, UPDATE)
4. ResultSet auswerten
getXXX("Spalte"); Methoden für alle primitiven Java-Datentypen
->getString() funktioniert immer!
while (rset.next()) {
System.out.println(“MNr.: ”+rset.getInt(‚MNr‘)+“ Land: “+rset.getString(2));
}
5. Ressourcen freigebe
close(); Methode
rset1.close();
stmt1.close();
con.close();