Advertisement
Guest User

Untitled

a guest
Jan 1st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.ResultSetMetaData;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. public class Connecting {
  9.  
  10.     public static Connection conn;
  11.     public Statement stmt;
  12.     public ResultSet rs;
  13.    
  14.  
  15. //    public Connecting() {
  16. //        try {
  17. //            conn = DriverManager.getConnection("jdbc:derby://localhost:1527/HMS", "ProDBA", "admin");
  18. //        } catch(SQLException e) {
  19. //            
  20. //        }
  21. //    }
  22.     public Connecting() {
  23.         try {
  24.             conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/fb_bots", "root", "");
  25.             System.out.println("successful");
  26.         } catch (SQLException e) {
  27.             e.printStackTrace();
  28.         }
  29.     }
  30.    
  31.     public void getelemtnts() {
  32.         try {
  33.             stmt = conn.createStatement();
  34.             String sql = "select * from account";
  35.             rs = stmt.executeQuery(sql);
  36.             ResultSetMetaData mt =  rs.getMetaData();
  37.            
  38.             while (rs.next()) {
  39.                 for (int i = 0; i < mt.getColumnCount(); i++) {
  40.                     System.out.print(rs.getString(i + 1) + " ");
  41.                 }
  42.                 System.out.println();
  43.             }
  44.         } catch(SQLException e) {
  45.            
  46.         }
  47.     }
  48.  
  49.     public static void main(String[] args) {
  50.         new Connecting().getelemtnts();
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement