Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class MySqlCode {
  4.  
  5. public static void main(String[] args) throws Exception {
  6. String usuario = "user";
  7. String password = "pass";
  8. String url = "jdbc:mysql://servidor:3306/db";
  9.  
  10. try (Connection conexion = DriverManager.getConnection(url, usuario, password);
  11. PreparedStatement ps = conexion.prepareStatement("select * from tbl");
  12. ResultSet rs = ps.executeQuery()) {
  13.  
  14. while (rs.next()) {
  15. System.out.printf(
  16. "%s-%s%n",
  17. rs.getString("col1"),
  18. rs.getString("col2"));
  19. }
  20. }
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement