Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Students : null null Falcone
- Students : null null Wayne
- Students : null null Parker
- Students : null null Grey
- Students : null null Norris
- Students : null null Kent
- package sqltest;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class SQLtest {
- private static final String url = "jdbc:mysql://localhost:3306/school_db?useTimezone=true&serverTimezone=GMT";
- private static final String user = "root";
- private static final String password = "123456";
- private static Connection con;
- private static Statement stmt;
- private static ResultSet rs;
- public static void main(String args[]) {
- String query = "SELECT student.id, student.name ,student.surname from student";
- try {
- con = DriverManager.getConnection(url, user, password);
- stmt = con.createStatement();
- rs = stmt.executeQuery(query);
- while (rs.next()) {
- int id = rs.getInt(1);
- String firstName = rs.getString(2);
- String lastName = rs.getString(3);
- String count = null;
- String firstname = null;
- System.out.println("Students : " + count + " " + firstname + " " + lastName);
- }
- } catch (SQLException sqlEx) {
- sqlEx.printStackTrace();
- } finally {
- try { con.close(); } catch(SQLException se) { }
- try { stmt.close(); } catch(SQLException se) { }
- try { rs.close(); } catch(SQLException se) { }
- }
- }
- }
Add Comment
Please, Sign In to add comment