- using m1 .
- using Eclipse.
- connected database and tomcat successfully.
[enter image description here][1]
There are two errors. (It seems like one problems)
1. HTTP 404
-> I rechecked tomcat path, java version, and locations. but It still doesn't work.
2. Page load failed with error: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.[enter image description here][3]
-> Some bloggers said info.plist should be revised. I revised info.plist like below but it doesn't work.
[enter image description here][4]
package product;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class productMgr {
public ArrayList<product> getProduct(int categoryID) throws SQLException, ClassNotFoundException {
ArrayList<product> products = new ArrayList<>();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
String sql = "select * from product where categoryId = ?";
String jdbcDriver = "**jdbc:mysql://address**";
String dbUser = "**root**";
String dbPwd = "**pw**";
conn = DriverManager.getConnection(jdbcDriver, dbUser, dbPwd);
stmt = conn.prepareStatement(sql);
stmt.setInt(1, categoryID);
rs = stmt.executeQuery();
while(rs.next()) {
String ProductID = rs.getString("productID");
int CategoryID = rs.getInt("categoryID");
String ProductName = rs.getString("productName");
int Price = rs.getInt("price");
int Amount = rs.getInt("amount");
products.add(new product(ProductID, CategoryID, ProductName, Price, Amount));
}
return products;
}catch (SQLException se) {
throw new RuntimeException("A database error occured. " + se.getMessage());
}catch (Exception e) {
throw new RuntimeException("Exception: " + e.getMessage());
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException se) {
se.printStackTrace(System.err);
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException se) {
se.printStackTrace(System.err);
}
}
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}
}
[1]: https://i.stack.imguenter code herer.com/Lo5t5.png [2]: https://i.stack.imgur.com/yxt4j.png [3]: https://i.stack.imgur.com/3SFJI.png [4]: https://i.stack.imgur.com/qDT3i.png