this error "
java.sql.SQLNonTransientConnectionException: The connection was refused because the database AnimeFigurineCollection [wimmy on WIMMY] was not found.
" keeps appearing even tho my database is connected, also when remove my derbyclient.jar this error disappears. idont know whats happening pls help
What I have tried:
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");
}
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;
}
public void insertProduct(Collection col){
try {
String queryStr = "Insert into ALBUM(Code, RegistrationNumber, Barcode, MainCharName, Title, Version, Type)"
+ "Values(?,?,?,?,?,?,?)";
ps = conn.prepareStatement(queryStr);
ps.setString(1, col.getCode());
ps.setInt(2, col.getRegistrationNumber());
ps.setInt(3, col.getBarcode());
ps.setString(4, col.getMaincharName());
ps.setString(5, col.getTitle());
ps.setString(6, col.getVersion());
ps.setString(7, col.getSize());
ps.execute();
JOptionPane.showMessageDialog(null, "Successfully added " + col.getCode() + ", "
+ col.getMaincharName() + ", " + col.getTitle()+ ", " + col.getVersion() + ", " + col.getSize());
} catch (SQLException ex) {
java.util.logging.Logger.getLogger(CollectionRepository.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
}
public void editProduct(Collection col) throws SQLException {
String queryStr = "UPDATE ALBUM"
+ " SET registrationNumber=?, barcode=?, maincharName=?, title=?, version=?, type=?"
+ " WHERE code=?";
ps = conn.prepareStatement(queryStr);
ps.setInt(1, col.getRegistrationNumber());
ps.setInt(2 , col.getBarcode());
ps.setString(3, col.getMaincharName());
ps.setString(4, col.getTitle());
ps.setString(5, col.getVersion());
ps.setString(6, col.getSize());
ps.setString(7, col.getCode());
ps.execute();
JOptionPane.showMessageDialog(null, "Successfully updated " + col.getMaincharName() + ", " + col.getTitle());
}
public void deleteStudent(String code) throws SQLException {
String queryStr = "DELETE FROM ALBUM"
+ " WHERE code=?";
ps = conn.prepareStatement(queryStr);
ps.setString(1, code);
ps.execute();
JOptionPane.showMessageDialog(null, "Successfully deleted ");
}
}