如何修复“java.sql.SQLNonTransientConnectionException:连接被拒绝,因为找不到数据库 AnimeFigurineCollection。”

问题描述 投票:0回答:1

我该如何解决这个问题?这是我到目前为止的代码

package case_study_3;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;

public class CollectionRepository {
    PreparedStatement ps;
    ResultSet rs;
    Connection conn;

    public CollectionRepository() {
    
    try {
        dbconn();
    } catch (SQLException ex) {
        java.util.logging.Logger.getLogger(CollectionRepository.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(CollectionRepository.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    try {
        conn.createStatement();
    } catch (SQLException ex) {
        java.util.logging.Logger.getLogger(CollectionRepository.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    
    }

   public void dbconn() throws SQLException, ClassNotFoundException {
    String url = "jdbc:derby://localhost:1527/AnimeFigurineCollection [wimmy on WIMMY]";
    String driver = "org.apache.derby.jdbc.ClientDriver";
    Class.forName(driver);
    conn = DriverManager.getConnection(url,"wimmy","1231");

    }//end db conn
    
    public List<Collection> getAllProduct(){
        List<Collection> col = new ArrayList<>();
        
        String queryStr = "Select * From ALBUM";
    try {
        ps = conn.prepareStatement(queryStr);
        rs = ps.executeQuery();
        while(rs.next()){
            Collection collect = new Collection(rs.getString("code"),
                    rs.getInt("registrationNumber"),
                    rs.getInt("barcode"),
                    rs.getString("maincharName"),
                    rs.getString("title"),
                    rs.getString("version"),
                    rs.getString("type"));
            col.add(collect);
        }
    } catch (SQLException ex) {
        java.util.logging.Logger.getLogger(CollectionRepository.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    
    
    }    
    return col;
    
}//end getall

此外,当我添加 derbyclient.jar 时,会出现以下情况:

java.sql.SQLNonTransientConnectionException:连接被拒绝,因为找不到数据库 AnimeFigurineCollection [wimmy on WIMMY]。 “错误 08004:连接被拒绝,因为找不到数据库 AnimeFigurineCollection [WIMMY 上的 wimmy]。”

如果我删除它,那两个也会消失。

java jdbc derby
1个回答
0
投票

检查您是否已创建名为

AnimeFigurineCollection

的数据库
© www.soinside.com 2019 - 2024. All rights reserved.