Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
- static final String URL = "jdbc:mysql://localhost:3306/Connection?autoReconnect=true&useSSL=false";
- static final String NAME = "root";
- static final String PASS = "pass";
- Connection connect = null;
- Statement statement = null;
- System.out.println("Registering JDBC driver...");
- Class.forName(JDBC_DRIVER);
- System.out.println("Creating database connection...");
- connect = DriverManager.getConnection(URL,NAME,PASS);
- System.out.println("Executing statement...");
- statement = connect.createStatement();
- String sql;
- sql = "SELECT city, target, sales FROM offices";
- ResultSet resultSet = statement.executeQuery(sql);
- while(resultSet.next()){
- String city = resultSet.getString("city");
- Double target = resultSet.getDouble("target");
- Double sales = resultSet.getDouble("sales");
- System.out.println(city);
- System.out.println(target);
- System.out.println(sales);
- }
- resultSet.close();
- statement.close();
- connect.close();
- }
Add Comment
Please, Sign In to add comment