Guest User

Untitled

a guest
Mar 13th, 2018
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. import java.beans.Statement;
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.ResultSet;
  11. public class databaseconnect {
  12.  
  13. public static void main(String args[]){
  14. try{
  15. Class.forName("com.mysql.jdbc.Driver");
  16. Connection con=DriverManager.getConnection(
  17. "jdbc:mysql://localhost:3306/jobportal1","root","root");
  18. //here sonoo is database name, root is username and password
  19. java.sql.Statement stmt=con.createStatement();
  20. ResultSet rs=stmt.executeQuery("select * from candidate");
  21. while(rs.next())
  22. System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
  23. con.close();
  24. }catch(Exception e){ System.out.println(e);}
  25. }
  26. }
Add Comment
Please, Sign In to add comment