Advertisement
Guest User

Untitled

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