Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. class MySQL {
  4.  
  5. public static void main(String args[]) {
  6. try {
  7. Class.forName("com.mysql.jdbc.Driver");
  8. Connection con=DriverManager.getConnection(
  9. "jdbc:mysql://localhost:3306/mata","root","root");
  10. //here mata is database name, root is username and password
  11. Statement stmt=con.createStatement();
  12. ResultSet rs=stmt.executeQuery("select * from emp");
  13. while(rs.next())
  14. System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
  15. con.close();
  16. }catch(Exception e){ System.out.println(e);}
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement