SQLite无法解析为某种类型

时间:2017-09-16 09:49:22

标签: sqlite jsp

我有SQLLite数据库。 DB的连接在SQLite.java类中。在ProductPage.jsp中,我创建了此类的实例。 错误是“SQLite无法解析为某种类型”。我使用Tomcat服务器。屏幕截图已附上。你能帮帮我吗?

SQLite.java

import java.sql.Connection;
import java.sql.DriverManager;

    public class SQLite {
    Connection con =null;

    public static Connection getConnection(){
        try{
            //Class.forName("org.sqlite.JDBC");

            //adjust database path
            Connection cn = DriverManager.getConnection("jdbc:sqlite:Lab_4.sqlite");
            System.out.println("Connection successful");
            return cn;
        }catch(Exception e){
            System.out.println("Error "+e.getMessage());
            return null;
        }       
    }
}

ProductPage.jsp

 <%@page import="java.sql.Connection"%>
    <%@page import="java.sql.PreparedStatement"%>
    <%@page import="java.sql.ResultSet"%>

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Product Table</title>
    </head>
    <body>



         <% Connection cn=new SQLite.getConnection();

            String  pid, name, price, stock, comments;      
            String query = ("SELECT * FROM T_PRODUCT");
            PreparedStatement pstmt = cn.prepareStatement(query);
            //pstmt.setInt(1, 2);
            ResultSet rs = pstmt.executeQuery(); %>

            <table border="2">
       <tr>
            <td>Product ID</td>
            <td>Product Name</td>
            <td>Product Price</td>
            <td>Product Stock</td>
            <td>Product Comments</td>
       </tr>
       <%  
       try
       {



           while(rs.next())
           {%>

           <tr><td><%out.println(rs.getInt("Prd_ID")); %></td></tr>
           <tr><td><%out.println(rs.getString("Prd _Name")); %></td></tr>
           <tr><td><%out.println(rs.getInt("Prd _Price")); %></td></tr>
           <tr><td><%out.println(rs.getInt("Prd _Stock")); %></td></tr>
           <tr><td><%out.println(rs.getString("Prd _Comments")); %></td></tr>


       <%
           }
       %>
       </table>
       <%
            cn.close();

       }
       catch(Exception e)
       {
            e.printStackTrace();
       }
       %>

    </body>
    </html>

Screenshot

1 个答案:

答案 0 :(得分:0)

您可以尝试通过SQLite.java标记导入<page>课程,即将以下内容添加到ProductPage.jsp的开头:

<%@ page import="SQLite" %>

如果你的SQLite.java课程实际上有一个包裹(你没有告诉我们),那么请使用:

<%@ page import="package.SQLite" %>

请注意,许多人认为导入JSP是不好的做法,它被认为违反了良好的MVC原则。