java嵌入式derby表/视图
我创建了 Embedded Derby 数据库,它给了我错误。尽管我有 APP 架构,其中
java.sql.SQLSyntaxErrorException: Table/View 'REST' does not exist.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
此处创建的 REST 表是 java 类:
public class Main
{
private static String dbURL = "jdbc:derby:tes;create=true";
private static String tableName = "REST";
// jdbc Connection
private static Connection conn = null;
private static Statement stmt = null;
public static void main(String[] args)
{
createConnection();
insertRestaurants(5, "LaVals", "Berkeley");
selectRestaurants();
shutdown();
}
private static void createConnection()
{
try
{
// System.setProperty("derby.system.home", "/Users/myuser/futbol");
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
//Get a connection
conn = DriverManager.getConnection(dbURL);
}
catch (Exception except)
{
except.printStackTrace();
}
}
private static void insertRestaurants(int id, String restName, String cityName)
{
try
{
stmt = conn.createStatement();
stmt.execute("insert into REST values (" +
id + ",'" + restName + "','" + cityName +"')");
stmt.close();
}
catch (SQLException sqlExcept)
{
sqlExcept.printStackTrace();
}
}
}
I created Embedded Derby database it give me error.although I have APP schema in which table REST created
java.sql.SQLSyntaxErrorException: Table/View 'REST' does not exist.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
here is java class:
public class Main
{
private static String dbURL = "jdbc:derby:tes;create=true";
private static String tableName = "REST";
// jdbc Connection
private static Connection conn = null;
private static Statement stmt = null;
public static void main(String[] args)
{
createConnection();
insertRestaurants(5, "LaVals", "Berkeley");
selectRestaurants();
shutdown();
}
private static void createConnection()
{
try
{
// System.setProperty("derby.system.home", "/Users/myuser/futbol");
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
//Get a connection
conn = DriverManager.getConnection(dbURL);
}
catch (Exception except)
{
except.printStackTrace();
}
}
private static void insertRestaurants(int id, String restName, String cityName)
{
try
{
stmt = conn.createStatement();
stmt.execute("insert into REST values (" +
id + ",'" + restName + "','" + cityName +"')");
stmt.close();
}
catch (SQLException sqlExcept)
{
sqlExcept.printStackTrace();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我知道我在这方面落后了四年,但我终于找到了如何解决我的问题(这就是为什么我在这个帖子上)。
我使用数据库脚本编辑器创建了表。我在桌子周围使用了双引号。当我进入服务选项卡(netbeans)并右键单击我的表以查看数据时,我发现了这一点。我得到了这个:
所以,我想我会把它翻译成我的java。还有,宾果。
希望这会对您的应用程序有所启发,我复制并粘贴了您的一些代码,希望这会起作用。
干杯!
I know I am four years behind on this, but I finally found out how I resolved my problem (hence why I am on this thread).
I created my table using the database script editor. I used double quotes around my table. I found this out when I went to the service tab (netbeans), and right clicked on my table to view data. I got this:
So, I thought I would translate that to my java. And, Bingo.
Hopefully this will shed some light on your application, I copied and pasted some of your code and hopefully this will work.
Cheers!
表名区分大小写。确保您创建的表实际上名为“REST”且全部大写,或者它是“Rest”或“rest”。
Table names are case sensitive. Make sure the table you created is actually called "REST" with all caps or if it's "Rest" or "rest".
我在嵌入式数据库方面遇到了同样的问题,最终清除了相同的问题。这肯定会对您有所帮助 aparna-java.blogspot.com 请检查此
I had the same trouble with embedded db and finally cleared the same .This will help you for sure aparna-java.blogspot.com please check this
一个简单的例子@ http://javabyranjith.blogspot.in /2016/08/apache-derby-with-java-example.html。希望它能有所帮助
A simple example @ http://javabyranjith.blogspot.in/2016/08/apache-derby-with-java-example.html. Hope it can be helpful
我使用 Eclipse 进行了以下修复:(
在数据库透视图:窗口>透视图>打开透视图>其他>数据库开发),右键单击数据库连接文件夹>新建>Derby:
您必须确保“数据库位置”文件夹位于与(编辑驱动程序定义 > JAR 列表)中提到的 Derby.jar 位置相同的位置。就像下面的快照一样:
Derby Jar 位置
Derby DB 位置
希望这会有所帮助。
I did the following fix, using Eclipse:
(In Database Perspective: Window>Perspective>Open Perspective>Other>Database Development), right clicking Database Connection folder>New>Derby:
You have to make sure the 'Database Location' folder is at the same location as the Derby.jar location mentioned at (Edit Driver Definition>JAR List). Like see below snapshot:
Derby Jar Location
Derby DB Location
Hope this helps.
您可能会发现从 Derby 教程开始学习 Derby 会更容易:http: //db.apache.org/derby/docs/10.7/getstart/cgstutorialintro.html
You might find it easier to learn Derby by starting with the Derby tutorials: http://db.apache.org/derby/docs/10.7/getstart/cgstutorialintro.html