Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Connecting {
- public static Connection conn;
- public Statement stmt;
- public ResultSet rs;
- // public Connecting() {
- // try {
- // conn = DriverManager.getConnection("jdbc:derby://localhost:1527/HMS", "ProDBA", "admin");
- // } catch(SQLException e) {
- //
- // }
- // }
- public Connecting() {
- try {
- conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/fb_bots", "root", "");
- System.out.println("successful");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void getelemtnts() {
- try {
- stmt = conn.createStatement();
- String sql = "select * from account";
- rs = stmt.executeQuery(sql);
- ResultSetMetaData mt = rs.getMetaData();
- while (rs.next()) {
- for (int i = 0; i < mt.getColumnCount(); i++) {
- System.out.print(rs.getString(i + 1) + " ");
- }
- System.out.println();
- }
- } catch(SQLException e) {
- }
- }
- public static void main(String[] args) {
- new Connecting().getelemtnts();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement