Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Statement stmt = null;
- ResultSet rs = null;
- Connection conn = null;
- try {
- conn =
- DriverManager.getConnection("jdbc:mysql://localhost/mydb?" +
- "user=root&password=glight28");
- System.out.println("Connected! oh yeah");
- //creare Statement che serve a fare le query
- stmt = conn.createStatement();
- //esecuzione query che -> salva risultato in rs che รจ un ResultSet
- rs = stmt.executeQuery("SELECT * FROM students");
- if (rs != null) {
- while (rs.next()) {
- System.out.println(rs.getString("Name"));
- }
- }
- } catch (SQLException ex) {
- // catturare errori
- System.out.println("SQLException: " + ex.getMessage());
- System.out.println("SQLState: " + ex.getSQLState());
- System.out.println("VendorError: " + ex.getErrorCode());
- }finally {
- rs = null;
- }
Add Comment
Please, Sign In to add comment