Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class SearchBeer {
- public static void main(String[] args) {
- String sql = "SELECT * FROM Beers WHERE Alcohol = 12.0 ORDER BY Alcohol";
- try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost/StudentDB?useSSL=false", "root", "WACHTWOORDINVULLEN")) {
- System.out.println("Connection OK\n");
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery(sql);
- while(rs.next()) {
- int id = rs.getInt(1);
- String beerName = rs.getString(2);
- int brewerId = rs.getInt(3);
- int categoryId = rs.getInt(4);
- double price = rs.getDouble(5);
- int stock = rs.getInt(6);
- double alcohol = rs.getDouble(7);
- int version = rs.getInt(8);
- System.out.printf("ID: %3d \tName: %-85s \t Brewer: %3d \t Category: %d \t %4.2f EUR \t Stock: %d \t %4.1f %% \t %d %n", id, beerName, brewerId, categoryId, price, stock, alcohol, version);
- }
- }
- catch (Exception ex) {
- System.out.println("Something went wrong!");
- ex.printStackTrace(System.err);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement