【发布时间】:2011-09-26 09:54:12
【问题描述】:
我第一次调试/运行应用程序时,我正在尝试使用 tomcat 运行我的应用程序,它的工作正常。但是当我第二次尝试运行时,我收到错误“XJ040”。
"Failed to start database 'C:\Documents and Settings\vitaly87\.netbeans- derby\articals' with class loader WebappClassLoader
context: /WebApplication1
delegate: false
repositories:
我认为问题是因为关闭连接有问题。因为当我停止服务器时,问题会消失,直到第二次运行。
这里是代码:
private Connection connect = null;
//private Statement stmt = null;
private PreparedStatement preparedStatement = null;
private ResultSet resultSet = null;
public ArrayList<story> stories=new ArrayList<story>();
void getStories(String version) throws SQLException{
try{
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
}catch(ClassNotFoundException e){
System.out.println(e);
}
connect = DriverManager.getConnection( "jdbc:derby:C:\\Documents and Settings\\vitaly87\\.netbeans-derby\\articals", "admin", "admin");
// statement = connect.createStatement();
int ArticlesId= Integer.parseInt(version);
preparedStatement = connect.prepareStatement("SELECT * FROM admin.articles where id>"+ArticlesId+"");
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
stories.add(new story(resultSet.getString("title"),resultSet.getString("date"),resultSet.getString("text")));
}
close();
}
//close connection
private void close() {
try {
if (resultSet != null) {
resultSet.close();
}
if (connect != null) {
connect.close();
}
} catch (Exception e) {
}
感谢您的帮助
【问题讨论】:
-
为什么不在 close 函数的开头放置一个 print 语句,看看它是否会运行。