Guest User

Untitled

a guest
Jun 16th, 2018
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import java.sql.DriverManager;
  2. import java.sql.ResultSet;
  3. import java.sql.SQLException;
  4.  
  5. import com.mysql.jdbc.ResultSetMetaData;
  6. import com.mysql.jdbc.Statement;
  7.  
  8. public class Connection {
  9.  
  10. public static void main(String[] args) {
  11.  
  12. String driver="com.mysql.jdbc.Driver";
  13.  
  14. try {
  15. Class.forName(driver);
  16.  
  17. java.sql.Connection con=null;
  18. String url="jdbc:mysql://localhost:3306/emp1";
  19. String user="root";
  20. String pwd="";
  21. java.sql.Statement st=null;
  22. ResultSet rs=null;
  23. con=DriverManager.getConnection(url,user,pwd);
  24. st=con.createStatement();
  25. String querry="select * from emp1";
  26. rs=st.executeQuery(querry);
  27. // java.sql.ResultSetMetaData rsm=rs.getMetaData();
  28. //int col=rsm.getColumnCount();
  29.  
  30. System.out.println(rs);
  31.  
  32.  
  33. while(rs.next())
  34. {
  35. // for(int i=0;i<col;i++)
  36. // {
  37. System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3));
  38. //}
  39.  
  40. }
  41.  
  42. } catch (ClassNotFoundException | SQLException e) {
  43. // TODO Auto-generated catch block
  44. e.printStackTrace();
  45. }
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. }
  55.  
  56. }
Add Comment
Please, Sign In to add comment