matias
matias

Reputation: 59

Connect to DB (Derby)

I try to connect to the database with this code:

      try
    {
        Class.forName("org.apache.derby.jdbc.ClientDriver");
        String url = "jdbc:derby://localhost:1527/sample";
        Connection con = DriverManager.getConnection(url);
        PreparedStatement pstmt=con.prepareStatement("insert into app.discount_code values('A',22)");
        pstmt.executeUpdate();
        con.close();
    }

    catch(Exception e)

    {
         System.out.println(e.getMessage());

    }

..but not result. What do I need to do to connect to the DB?

Upvotes: 0

Views: 443

Answers (1)

Clark Bao
Clark Bao

Reputation: 1693

Sir, You are connecting to derby network server. So you need to firstly config the environment and start the network server. Please also check the jdbc driver jars are correct.

About how to config and start derby network server.Look at here. http://db.apache.org/derby/papers/DerbyTut/ns_intro.html#ns_config_env

Also you'd better put the close method in your finally block.

You'd better paste your error message, it wil be helpful to find your problem.

Upvotes: 1

Related Questions