Advertisement
Guest User

Untitled

a guest
Sep 14th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7. public class ConnectionMySQL {
  8.  
  9. public static void main(String a[]){
  10.  
  11. try {
  12. Connection conn = DriverManager.getConnection("jdbc:mysql://10.22.40.134:3306//foo","test","1234");
  13. String query = "SELECT * FROM student table";
  14. Statement stmt = conn.createStatement();
  15. ResultSet rs = stmt.executeQuery(query);
  16. while(rs.next()){
  17. System.out.println("Student ID :"+rs.getString("s_id")+" Name :"+rs.getString("s_name")+"Class :"+rs.getString("s_class")+"Mobile no :"+rs.getString("s_mobile"));
  18. }
  19. } catch (Exception e){
  20. System.err.println(e);
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement