Reputation: 1
My Java code is not compiling:
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.COnnection;
import java.sql.SQLException;
public class CreateTable {
public static void main(String args[]) {
final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
final String CONNECTION = "jdbc:derby:AccountDatabase;create=true";
try {
Class.forName(DRIVER).newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try (Connection connection = DriverManager.getConnection(CONNECTION);
Statement statement = connection.createStatement()) {
statement.executeUpdate(
"create table ACCOUNTS "
+ " (NAME VARCHAR(32) NOT NULL PRIMARY KEY, "
+ " ADDRESS VARCHAR(32), "
+ " BALANCE FLOAT) ");
statement.executeUpdate(
"insert into ACCOUNTS values "
+ " ('Bill Gates', 'pluto', 1.000.000)");
statement.executeUpdate(
"insert into ACCOUNTS values "
+ " ('Steve Jobs', 'Mars', 1.000.000)");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
I have java 7 and jre version 7 both are compatible. Above is the CreateTable.java it compiles just fine. But when I run for the firsttime on the embedded server this is how I run it(it is the CreateTable.class without the class by the way):
c:\programming\programs\Database Table>java -cp .;"\Program Files\Java\jdk1.7.0_06\db\lib\derby.jar" CreateTable
This is the error that I receive this error in java:
java.sql.SQLSyntaxErrorException: Syntax error: Encountered ".000" at line 1, column 118.
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.executeUpdate(Unknown Source)
at CreateTable.main(CreateTable.java:33)
Caused by: java.sql.SQLException: Syntax error: Encountered ".000" at line 1, column 118.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransport
AcrossDRDA(Unknown Source)
... 9 more
Caused by: ERROR 42X01: Syntax error: Encountered ".000" at line 1, column 118.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.ParserImpl.parseStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
... 3 more
The Database is created and everything and I thought that I would still be able to retrieve the data but apparently not. I must compile completely with no errors, in order to retrieve this data. Can someone please help configure this correctly so that it compiles correctly?
I can also post the GetData.java code if you need it also but I do not think it is necessary. I'm 99% sure that I will need the createTable.class to run correctly before my GetData.java code can be utilized. Please help? Any ideas as to why this occurs.
I also tried to recompile and I get an error like this:
java.sql.SQLException: Table/View 'ACCOUNTS' already exists in Schema 'APP'.
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.executeUpdate(Unknown Source)
at CreateTable.main(CreateTable.java:27)
Caused by: java.sql.SQLException: Table/View 'ACCOUNTS' already exists in Schema 'APP'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransport AcrossDRDA(Unknown Source)
... 10 more
Caused by: ERROR X0Y32: Table/View 'ACCOUNTS' already exists in Schema 'APP'.
at 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.open(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
... 4 more
Upvotes: 0
Views: 767
Reputation: 1728
1.000.000
is your problem. .
is a decimal fraction separator, not thousands separator.
Upvotes: 1