简体   繁体   中英

unable to connect in derby database(embedded) using netbeans

    try { 
 Connection con;
 con = DriverManager.getConnection("jdbc:derby:C:/Users/family/.netbeans-derby/MyDatabase;create=true");
 System.out.println("Id");
 PreparedStatement stmt;
 stmt = con.prepareStatement("Select * from PERSON;");
 ResultSet rs=stmt.executeQuery();
 while(rs.next())
            {
              String id=rs.getString(String.valueOf("ID"));
              String name=rs.getString("NAME");
              System.out.println(id);
              System.out.println(name);
            }

        }catch (SQLException err) {
           System.out.println(err.getMessage()+ "No matching word in database");
        }

Hi, I'm a newbie to java derby. I have read forums regarding on connecting derby database(embedded) in netbeans but still i didn't find the solution. I have already add the derby.jar and derbyclient.jar in the library but still the error reads this way, can someone help me fix this error:

errorcode:

Failed to start database 'C:/Users/family/.netbeans-derby/fine' with class loader sun.misc.Launcher$AppClassLoader@1a7bf11, see the next exception for details.No matching word in database

Hope someone will respond to my question, Thanks..!!

First, I believe you mixed up usage of prepareStatement vs. Statment Take a look at this link, so you get some ideas how to learn more. Difference between Statement and PreparedStatement

Second, with your SQL query you cannot use prepareStatment. If I understood what you want to do, your SQL query should look like this.

String sql = "Select * from PERSON WHERE Id=?";

another issue about your SQL query is not to mentin what shcema you used. becasue PERSON does not make sense here, it should be something like APP.PERSON

Try to take a look at this tutorial about how to use perparStatment in JDBC http://www.mkyong.com/jdbc/jdbc-preparedstatement-example-batch-update/

Third, I had an issue about where I should I create my database, so I advice you to creat it in side of the project folder. hint, use relative path in your getConncetion

At the end, you need to have more research because you got it all wrong. good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM