Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class Driver {
- public static void main(String[] args) throws SQLException {
- Connection myConn = null;
- Statement myStmt = null;
- ResultSet myRs = null;
- try {
- // 1. Creo una connessione al Database
- myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/prova", "root" , "home");
- // 2. Creo uno Statement
- myStmt = myConn.createStatement();
- // 3. Eseguo le Query SQL
- myRs = myStmt.executeQuery("select * from studenti");
- // 4. Elaboro il risultato
- while (myRs.next()) {
- System.out.println(myRs.getString("Nome") + ", " + myRs.getString("Cognome"));
- }
- }
- catch (Exception exc) {
- exc.printStackTrace();
- }
- finally {
- if (myRs != null) {
- myRs.close();
- }
- if (myStmt != null) {
- myStmt.close();
- }
- if (myConn != null) {
- myConn.close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement