Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SelectExample {
- public static void main(String[] args) throws ClassNotFoundException {
- Connection connection = null;
- try {
- // load driver
- Class.forName("com.mysql.jdbc.Driver");
- // tao ket noi
- connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "");
- // truy van
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery("SELECT * from student");
- while(resultSet.next()) {
- System.out.println(resultSet.getString("student_code"));
- System.out.println(resultSet.getString("name"));
- System.out.println(resultSet.getString("class"));
- System.out.println(resultSet.getString("faculty"));
- }
- } catch (SQLException e) {
- System.err.println(e);
- }finally {
- // dong ket noi
- if(connection != null)
- try {
- connection.close();
- } catch (SQLException e) {
- System.err.println(e);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement