Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 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. package oscop;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.PreparedStatement;
  11. import java.sql.ResultSet;
  12. import java.sql.SQLException;
  13. import java.sql.Statement;
  14. /**
  15.  *
  16.  * @author dani
  17.  */
  18. public class Oscop {
  19.  
  20.     public static void main(String[] args) {
  21.        Connection connection = null;
  22.        try {
  23.            Class.forName("com.mysql.jdbc.Driver");
  24.            connection = DriverManager.getConnection("jdbc:mysql://10.42.0.1:3306/user", "android", "oscop");
  25.                String sql;
  26.                sql = "SELECT * FROM user";
  27.                Statement statement = connection.createStatement();
  28.                ResultSet ps = statement.executeQuery(sql);
  29.                while(ps.next()) {
  30.                     System.out.println(ps.getInt(1)+""+ ps.getString(2) +""+ps.getString(3));
  31.                     connection.close();
  32.                }
  33.        } catch (Exception e) {
  34.            e.printStackTrace();
  35.        }
  36.    }
  37.    
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement