0

我有一个 Java 网站的 MVC 项目。

我在 Eclipse 中编码,我使用 Tomcat 和 derby 数据库。

我有以下javabean:

package collaboration;
import java.sql.*;
import org.apache.derby.jdbc.ClientDriver;

public class Modello {



    private String tipoInfo;
        private String ur = "jdbc:derby:/Users/sample;create=true";
        private String us = "ciao";
        private String p = "ciao";

        public Modello(){
            this.tipoInfo = "sconosciuto";
        }

        public String getTipoInfo(){
            return this.tipoInfo;
        }

        public void setTipoInfo(String tipoInfo){
            this.tipoInfo = tipoInfo;
        }

        public String getCatalogo(){

            String risultato = null;

            try{

                DriverManager.registerDriver(new ClientDriver());
                Connection connect = DriverManager.getConnection(ur, us, p);
                PreparedStatement statement = connect.prepareStatement("select titolo, autore, prezzo from libreria.libro");
                ResultSet controllo = statement.executeQuery();

                while(controllo.next()){
                    risultato += controllo.getString(1);
                }

                connect.close();

            } catch(Exception e){
                System.out.println(e);
            }

            return risultato;
        }

        public static void main(String[] args){
            Modello ciao = new Modello();
            System.out.println(ciao.getCatalogo());
        }

}

如果我将此代码作为 java 程序单独运行,则它可以正常工作。但是,如果我在 Tomcat 服务器上的 JSP 页面中将它用作 javabean,我会遇到这个问题:java.sql.SQLException: No suitable driver found for jdbc:derby:/Users/sample;create=true

这是用于 JSP 中的 javabean 的代码。

<%@page import="collaboration.Modello"%>
<jsp:useBean id="model" scope="page" class="collaboration.Modello" />
<jsp:setProperty name="model" property="*" />
<jsp:getProperty name="model" property="catalogo" />

有什么事?

4

0 回答 0