0

Kindly forgive the poor presentation and unethical coding lines if any

I'm trying to create my first jdbc class using embedded derby driver, I have created a maven project and added the following dependency

    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <version>10.11.1.1</version>
    </dependency>

I created a derby database in eclipse database developer, the ping to the database was successful, created a table and inserted values into it.

When I run the below java program

import java.sql.*;
import org.apache.derby.jdbc.*;

public class SiteDao implements SiteDaoInterface {
    
    
    public static void main(String[] args)
    {
        String url ="jdbc:derby:C://Users//shash//MyDB;create=true";
        String username="xyz";
        String password="xyz";
        String query="select * from practise.abc";
        //Class.forName("org.apache.derby.jdbc.ClientDriver")
        try {
            //Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
            //DriverManager.registerDriver(new org.apache.derby.jdbc.EmbeddedDriver());
            Connection con=DriverManager.getConnection(url,username,password);
            Statement st= con.createStatement();
            ResultSet rs=st.executeQuery(query);
            int i,j;
            while(  rs.next())
            {
                    i=rs.getInt(1);
                    j=rs.getInt(2);
                    System.out.println("data is"+i+","+j);
            }
            st.close();
            con.close();
        } catch (SQLException  e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

I'm encountering the below error.

Exception in thread "main" java.lang.NoSuchMethodError: 'void org.apache.derby.iapi.services.i18n.MessageService.setFinder(org.apache.derby.iapi.services.i18n.BundleFinder)'
    at org.apache.derby.impl.services.monitor.BaseMonitor.runWithState(Unknown Source)
    at org.apache.derby.impl.services.monitor.FileMonitor.<init>(Unknown Source)
    at org.apache.derby.iapi.services.monitor.Monitor.startMonitor(Unknown Source)
    at org.apache.derby.iapi.jdbc.JDBCBoot.boot(Unknown Source)
    at org.apache.derby.jdbc.EmbeddedDriver.boot(Unknown Source)
    at org.apache.derby.jdbc.EmbeddedDriver.<clinit>(Unknown Source)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:377)
    at com.smedia.dao.SiteDao.main(SiteDao.java:17)

I tried to go through the class mentioned in the error but encountered the below issue

no source attached

I tried many solutions offered on internet but it didn't work

I'm using java 15.0.1 and even tried using derby-10.15.2.0 as suggested in some stackoverflow solutions but it didn't work (moreover there is no EmbeddedDriver class in 10.15.x.x version to my surprise) Please let me know where am I ruining the code?

James Z
  • 12,209
  • 10
  • 24
  • 44
  • 2
    First question: Why using such an old version of derby? https://db.apache.org/derby/ https://search.maven.org/artifact/org.apache.derby/derby Furthermore you stated that there is no embedded driver class in 10.15.x.x which is simply wrong: https://search.maven.org/classic/#search%7Cga%7C1%7Cfc%3A%22org.apache.derby.jdbc.EmbeddedDriver%22 – khmarbaise Jan 08 '21 at 17:08
  • If you're using Java 15, you definitely need Derby 10.15. More here: https://stackoverflow.com/a/57221011/193453 – Bryan Pendleton Jan 08 '21 at 23:48
  • Thanks, didn't know that derby-tools jar must be included as well, will include the jar and check if the program is working fine – HelpMeLearn Jan 09 '21 at 02:31
  • Thanks it worked when I included derbytools jar – HelpMeLearn Jan 09 '21 at 02:47

0 Answers0