java和mysql连接问题http404

ntjbwcob  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(129)

使用m1。
使用eclipse。
已成功连接数据库和tomcat。
[在此处输入图像描述][1]
有两个错误(这似乎是一个问题)
1.http 404
->我重新检查了tomcat路径、java版本和位置。但它仍然不起作用。
2.页面加载失败,错误:无法加载资源,因为应用程序传输安全策略要求使用安全连接。[在此处输入图像描述][3]
->一些博客说info.plist应该修改。我修改了info.plist,如下所示,但它不起作用。
[在此处输入图像描述][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 代码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

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题