我从网上复制了这段代码,并为我的数据库做了一些必要的更改
public class MainClass {
静态连接连接;
public static void main(String[] args) throws Exception { if (args.length != 2) { System.out.println("Usage: java JavaDBDemo"); System.exit(1); }
String driver = "org.apache.derby.jdbc.EmbeddedDriver";
String dbName = "JeeteshBD";
String connectionURL = "jdbc:derby:" + dbName + ";";
String createString = "CREATE TABLE SANKYA.ADDRESS (NAME VARCHAR(32) NOT NULL, ADDRESS VARCHAR(50) NOT NULL)";
Class.forName(driver);
conn = DriverManager.getConnection(connectionURL);
Statement stmt = conn.createStatement();
stmt.setPoolable(true);
stmt.execute(createString);
PreparedStatement psInsert = conn
.prepareStatement("insert into SANKYA.ADDRESS values (?,?)");
psInsert.setString(1, args[0]);
psInsert.setString(2, args[1]);
psInsert.executeUpdate();
Statement stmt2 = conn.createStatement();
ResultSet rs = stmt2.executeQuery("select * from SANKYA.ADDRESS");
System.out.println("Addressed present in your Address Book\n\n");
int num = 0;
while (rs.next()) {
System.out.println(++num + ": Name: " + rs.getString(1) + "\n Address"
+ rs.getString(2));
}
rs.close();
} }
执行以下代码后,我在控制台中收到以下错误。
Exception in thread "main" java.sql.SQLException: Table/View 'ADDRESS' already exists in Schema 'SANKYA'.
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.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at MainClass.main(MainClass.java:26)
原因:java.sql.SQLException:表/视图“地址”已存在于模式“SANKYA”中。在 org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source) ... 10 更多原因:错误 X0Y32:表/视图架构“SANKYA”中已存在“地址”。在 org.apache.derby.iapi.error.StandardException.newException(Unknown Source) at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.duplicateDescriptorException(Unknown Source) at org.apache.derby.impl.sql.catalog .DataDictionaryImpl.addDescriptor(Unknown Source) at org.apache.derby.impl.sql.execute.CreateTableConstantAction.executeConstantAction(Unknown Source) at org.apache.derby.impl.sql.execute.MiscResultSet。
但是当我查看 Eclipse 中的数据库透视图时,更新还没有完成,任何人都可以对此有所了解吗?
这是在桌面上创建的 derby.log
----------------------------------------------------------------
2013-03-11 05:10:17.241 GMT:引导 Derby 版本 Apache 软件基金会 - Apache Derby - 10.5.1.1 - (764942):数据库目录 /home/sankya/JeeteshBD 上的实例 c013800d-013d-57db-3673-0000018a21b0
数据库类加载器已启动 - derby.database.classpath=''
格林威治标准时间 2013-03-11 05:10:17.639:
关闭实例 c013800d-013d-57db-3673-0000018a21b0
2013-03-11 05:10:27.773 GMT:引导 Derby 版本 Apache 软件基金会 - Apache Derby - 10.5.1.1 - (764942):数据库目录 /home/sankya/JeeteshBD 上的实例 a816c00e-013d-57db-3673-0000018a21b0
数据库类加载器已启动 - derby.database.classpath=''
格林威治标准时间 2013 年 3 月 11 日 06:22:45.639: