だから、javabean(ProductDataBean.java)を介してmysqlデータベースからデータを取得しようとしているjspファイル(ShowProducCatalog.jsp)があります。私は netbeans IDE を使用しています。NetBeans ID からテーブルを作成し、mysql ワークベンチで同じテーブルを表示して、サーバーが実行されていることを確認しました。しかし、アプリケーションを起動するたびにこのエラーが発生します
org.apache.jasper.JasperException: An exception occurred processing JSP page /ShowProductCatalog.jsp at line 9
6:
7: <html>
8: <body>
9: <% List productList = data.getProductList();
10: Iterator prodListIterator = productList.iterator();
11: %>
12:
そして、根本的な原因は私の豆の根本的な原因からです
java.lang.NullPointerException
cart.ProductDataBean.getProductList(ProductDataBean.java:36)
org.apache.jsp.ShowProductCatalog_jsp._jspService(ShowProductCatalog_jsp.java:81)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
エラーが発生する ProductDataBean セクションは次のとおりです。
public class ProductDataBean implements Serializable
{
private static Connection connection;
public ProductDataBean()
{
try
{
String userName = "root";
String password = "root";
String url = "jdbc:mysql://localhost:/eshopdb";
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(url,userName,password);
System.out.println("Database connection established");
}catch(Exception e){e.printStackTrace();}
}
public static Connection getConnection()
{
return connection;
}
public ArrayList getProductList() throws SQLException
{
ArrayList productList = new ArrayList();
Statement statement = connection.createStatement();//ERROR HERE
ResultSet results = statement.executeQuery("SELECT * FROM product");
while (results.next())
{...
接続変数が初期化されていないようです。しかし、私のユーザー名、パスワード、および URL は正しいです。助けてください!