Advertisement
Guest User

Untitled

a guest
Mar 7th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. package com.company.database;
  2.  
  3. import java.sql.*;
  4.  
  5. /**
  6. * Created by Tomek on 3/7/2016.
  7. */
  8. public class MySQLAccess {
  9.  
  10. private Connection connection;
  11. private Statement statement;
  12. private PreparedStatement preparedStatement;
  13. private ResultSet resultSet;
  14.  
  15.  
  16. public void readDatabase() throws Exception{
  17.  
  18. try{
  19. //ladowanie sterownika bazy danych
  20. Class.forName("com.mysql.jdbc.Driver");
  21. connection = DriverManager.getConnection("jdbc:mysql//localhost:82/nauka?"
  22. +"user=root&password=");
  23. statement = connection.createStatement();
  24.  
  25. resultSet = statement.executeQuery("select * from student");
  26. writeResultSet(resultSet);
  27.  
  28. } catch (Exception e){
  29. throw e;
  30. } finally {
  31.  
  32. }
  33. }
  34.  
  35. public void writeResultSet(ResultSet resultSet) throws SQLException
  36. {
  37. while (resultSet.next())
  38. {
  39. String id_stud = resultSet.getString("id_stud");
  40. String name = resultSet.getString("name");
  41. String surname = resultSet.getString("surname");
  42. String birth_date = resultSet.getString("birth_date");
  43. String semester = resultSet.getString("semester");
  44.  
  45. System.out.println(id_stud + name + surname + birth_date+semester + semester);
  46.  
  47. }
  48.  
  49. }
  50.  
  51.  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement