Advertisement
Guest User

Untitled

a guest
Mar 11th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. public static void main(String[] args) {
  2. Connection connection2 = null;
  3. Statement statement2 = null;
  4. ResultSet resultSet2 = null;
  5.  
  6. try {
  7. connection2 = (Connection) DriverManager.getConnection(
  8. "jdbc:mysql://localhost/ИМЯ", "ЛОГИН", "ПАРОЛЬ");
  9. } catch (SQLException se) {
  10. }
  11.  
  12. try {
  13. statement2 = connection2.createStatement();
  14. } catch (SQLException se) {
  15. se.printStackTrace();
  16. }
  17.  
  18. try {
  19. resultSet2 = statement2.executeQuery("SELECT * FROM userdetails");
  20. } catch (SQLException se) {
  21. se.printStackTrace();
  22. }
  23.  
  24. try {
  25. ResultSetMetaData rsmd = resultSet2.getMetaData();
  26. int columns = rsmd.getColumnCount();
  27. for (int i = 1; i <= columns; i++)
  28. System.out.printf("%-8st", rsmd.getColumnName(i) + " ");
  29. System.out.println();
  30. for (; resultSet2.next();) {
  31. for (int j = 1; j <= columns; j++)
  32. System.out
  33. .printf("%-8st", resultSet2.getObject(j) + " ");
  34. System.out.println();
  35. }
  36. } catch (SQLException e) {
  37. e.printStackTrace();
  38. } finally {
  39. try {
  40. connection2.close();
  41. statement2.close();
  42. resultSet2.close();
  43. } catch (SQLException se) {
  44. se.printStackTrace();
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement