我有一个用于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:没有为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" />
怎么回事?