德比模式错误[英] Derby Schema Error

本文是小编为大家收集整理的关于德比模式错误的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在尝试将数据插入我的桌面应用程序中的derby嵌入式数据库.但是德比给我带来了架构的错误,找不到错误. 我试图根据用户名创建模式来解决错误,但不能解决我的问题.我搜索了互联网,但是没有给定的解决方案解决了我的问题.

package derbyd.ui;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


public class AddStudent extends javax.swing.JFrame {

private void bt_saveActionPerformed(java.awt.event.ActionEvent evt) {                                        
    String conURL = "jdbc:derby:myDB;create=true";
    String user = "SOURABH";
    String passwd = "pass";
    Connection con = null;
    Statement st = null;
    String query;
    ResultSet rs = null;
    try
    {
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        con = DriverManager.getConnection(conURL, user, passwd);
        st = con.createStatement();
        System.out.println("Connection established");
        query = "INSERT INTO SOURABH.MyTable VALUES('"+txt_name.getText()+"','"+txt_surname.getText()+"')";
        st.executeUpdate(query);
        System.out.println("Added Successfully");
    }
    catch(Exception e)
    {
        System.out.println("Error ->"+e);
    }
}                                       


}

推荐答案

根据 apache derby的常见问题,您将看到:

模式仅由CREATE SCHEMA创建或在该模式中创建对象(表等)(这是隐式架构创建).

在代码中,您需要先创建表格,然后像魅力一样工作.

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
con = DriverManager.getConnection(conURL, user, passwd);
st = con.createStatement();
System.out.println("Connection established");

st.executeUpdate("CREATE TABLE MyTable" +
        "(name VARCHAR(255), surname varchar(255))");
System.out.println("Table created");

query = "INSERT INTO SOURABH.MyTable VALUES(" +
        "'" + txt_name.getText() + "','" + txt_surname.getText() + "')";
st.executeUpdate(query);
System.out.println("Added Successfully");

输出为:

Connection established
Table created
Added Successfully

如果您不止一次运行此语句,则会出现错误,因为该表已经存在.为了解决这个问题,在这里.

其他推荐答案

最简单的解决方案是配置您的数据库属性并使模式与用户名相同,但在资本垃圾中 前任: 模式应用程序 用户应用

希望我的答案能有所帮助.

本文地址:https://www.itbaoku.cn/post/597356.html

问题描述

I am trying to insert data into Derby embedded database for my Desktop Application. But Derby is giving me error of Schema Not found error. I have tried to solve error by creating schema as per username, but does not solve my problem. I searched internet, but none of given solution solved my problem.

package derbyd.ui;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


public class AddStudent extends javax.swing.JFrame {

private void bt_saveActionPerformed(java.awt.event.ActionEvent evt) {                                        
    String conURL = "jdbc:derby:myDB;create=true";
    String user = "SOURABH";
    String passwd = "pass";
    Connection con = null;
    Statement st = null;
    String query;
    ResultSet rs = null;
    try
    {
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        con = DriverManager.getConnection(conURL, user, passwd);
        st = con.createStatement();
        System.out.println("Connection established");
        query = "INSERT INTO SOURABH.MyTable VALUES('"+txt_name.getText()+"','"+txt_surname.getText()+"')";
        st.executeUpdate(query);
        System.out.println("Added Successfully");
    }
    catch(Exception e)
    {
        System.out.println("Error ->"+e);
    }
}                                       


}

推荐答案

According to the Frequently Asked Questions of Apache Derby, you will see that:

A schema is only created by CREATE SCHEMA or creating an object (table etc.) in that schema (this is implicit schema creation).

In your code, you need create the table first and then work like a charm.

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
con = DriverManager.getConnection(conURL, user, passwd);
st = con.createStatement();
System.out.println("Connection established");

st.executeUpdate("CREATE TABLE MyTable" +
        "(name VARCHAR(255), surname varchar(255))");
System.out.println("Table created");

query = "INSERT INTO SOURABH.MyTable VALUES(" +
        "'" + txt_name.getText() + "','" + txt_surname.getText() + "')";
st.executeUpdate(query);
System.out.println("Added Successfully");

The output is:

Connection established
Table created
Added Successfully

If you run this statement more than once, you'll get an error because the table already exists. To deal with that, here.

其他推荐答案

the easiest solution is to configure your database properties and make schema the same as user name but in capital litters ex: schema APP user app

hope my answer can help.