How can I fix this? This is my code so far

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

Also when I add my derbyclient.jar this appears:

java.sql.SQLNonTransientConnectionException: The connection was refused because the database AnimeFigurineCollection [wimmy on WIMMY] was not found. ""ERROR 08004: The connection was refused because the database AnimeFigurineCollection [wimmy on WIMMY] was not found."

If I remove it, those two disappears also.

1

There are 1 best solutions below

2
Magno Dev On

Check if you have created a database named AnimeFigurineCollection