daily pastebin goal
73%
SHARE
TWEET

Untitled

a guest Oct 2nd, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class JavaDBConnect {
  2.  
  3.     public static void main(String[] args) throws SQLException {
  4.  
  5.          try {
  6.             Class.forName("com.mysql.jdbc.Driver");
  7.             Connection con = (Connection) DriverManager.getConnection ("jdbc:mysql://YOUR DB URL", "root", "");
  8.  
  9.             Statement stmt = (Statement) con.createStatement();  
  10.  
  11.             ResultSet rs=stmt.executeQuery("select * from users");  
  12.  
  13.             while(rs.next())  
  14.  
  15.             System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  
  16.             con.close();  
  17.  
  18.             }
  19.          catch(Exception e){
  20.              System.out.println(e);
  21.             }
  22.         }
  23.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top