Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author 10154282
- */
- import static java.lang.System.out;
- import java.sql.*;
- import java.text.NumberFormat;
- class GetData {
- public static void main(String args[]) {
- NumberFormat currency =
- NumberFormat.getCurrencyInstance();
- final String DRIVER = "com.mysql.jdbc.Driver";
- final String CONNECTION =
- "jdbc:mysql://busman.britafe.vic.edu.au/DB_jarrods?" +
- "user=jarrods&password=jarrod";
- try {
- Class.forName(DRIVER).newInstance();
- } catch (InstantiationException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- try (Connection connection =
- DriverManager.getConnection(CONNECTION);
- Statement statement =
- connection.createStatement();
- ResultSet resultset =
- statement.executeQuery(
- "select * from ACCOUNTS")) {
- while(resultset.next()) {
- out.print(resultset.getString("NAME"));
- out.print(", ");
- out.print(resultset.getString("ADDRESS"));
- out.print(" ");
- out.println(currency.format(
- resultset.getFloat("BALANCE")));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement