-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdb.java
37 lines (24 loc) · 1.1 KB
/
db.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
public class ProductComponent {
public void printProductList(double lowPrice, double highPrice) throws Exception {
try (Connection connection =
DriverManager.getConnection("jdbc:mysql://database-1.c83fdlzp5lmg.us-east-2.rds.amazonaws.com:3306/classicmodels?"
+ "user=admin&password=admin987&serverTimezone=UTC");
PreparedStatement preparedStatement = connection
.prepareStatement("SELECT * FROM products "
+ "WHERE buyPrice BETWEEN ? AND ?");) {
preparedStatement.setDouble(1, lowPrice);
preparedStatement.setDouble(2, highPrice);
try (ResultSet resultSet = preparedStatement.executeQuery();) {
while (resultSet.next()) {
String name = resultSet.getString("productName");
System.out.println(name);
}
}
}
}
}