• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Can't set up the Database with code (from OCP study guide)

 
Rancher
Posts: 127
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there    Happy New Year    
So I'm trying to do the steps on page 509 in Boyarsky/Selikoff OCP study guide, but it is not working.
First I set up the path variable for .jar file (but I do not have any jar file, where should I take it?)
Second I wrote the class SetupDerbyDatabase in the file SetupDerbyDatabase.java and saved it just where should be .jar file, so:
C:\Program Files\Java\jdk1.8.0_251\db\lib
Third I've compiled it and the .class file is there
Fourth I try to execute this java -cp "C:\Program Files\Java\jdk1.8.0_251\db\lib\derby.jar;." SetupDerbyDatabase
but compiler return me that:


I also wrote the MyFirstDatabaseConnection class (page 513) in Eclipse and then I've tried to start it but have the same Exception.
Please help!
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, aside from I neither own the book nor know it - but putting some dev-code somewhere in C:\Program Files doesn't look right AT ALL.
Maybe share some instructions for those not having the book handy to know what the book tells you to do and then post what you actually have done. I'm sure the instructions of the book are well tested so when follow them in order it should work on the first try.
In addition, although this is a topic many already have debated about: I personal don't like the idea to use an IDE without knowing the basics to get something simple like this done on the terminal.
 
Mike Savvy
Rancher
Posts: 127
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I know how does terminal works but I do not really understand the steps in the book. They speak about derby.jar file but I do not know where should I find it. I did not found it on the website selikoff.com/ocp.
Also they speak about adding a path variable and give the path but no name for this variable. I'll try to post the text abd the code
 
Mike Savvy
Rancher
Posts: 127
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before running the following code, you need to add a .jar file to your classpath. Add <JAVA_HOME>/db/lib/derby.jar to your classpath. Just make sure to replace <JAVA_ HOME> with the actual path on your file system. On Linux or Mac, you run the program like this:

And on Windows, you run the program like this:

The code is as follows. You can also find this code along with more details on setup at http://selikoff.net/ocp.


Here is example of using this DB:

 
Master Rancher
Posts: 4068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the console I get when I run the code:



D:\JavaDevelopment\Testing\DataBase\db-derby-10.14.2.0-bin>java -cp .;lib\derby.jar SetupDerbyDataBase
Exception in thread "main" java.sql.SQLDataException: The syntax of the string representation of a date/time value is incorrect.
       at org.apache.derby.impl.jdbc.SQLExceptionFactory.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.executeLargeUpdate(Unknown Source)
       at org.apache.derby.impl.jdbc.EmbedStatement.executeUpdate(Unknown Source)
       at SetupDerbyDataBase.main(SetupDerbyDataBase.java:21)
Caused by: ERROR 22007: The syntax of the string representation of a date/time value is incorrect.
       at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
       at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
       at org.apache.derby.iapi.types.DateTimeParser.parseInt(Unknown Source)
       at org.apache.derby.iapi.types.SQLTimestamp.parseDateOrTimestamp(Unknown Source)
       at org.apache.derby.iapi.types.SQLTimestamp.parseTimestamp(Unknown Source)
       at org.apache.derby.iapi.types.SQLTimestamp.<init>(Unknown Source)
       at org.apache.derby.iapi.types.SQLChar.getTimestamp(Unknown Source)
       at org.apache.derby.iapi.types.SQLChar.getTimestamp(Unknown Source)
       at org.apache.derby.iapi.types.SQLTimestamp.setFrom(Unknown Source)
       at org.apache.derby.iapi.types.DataType.setValue(Unknown Source)
       at org.apache.derby.iapi.types.DataType.normalize(Unknown Source)
       at org.apache.derby.iapi.types.DataTypeDescriptor.normalize(Unknown Source)
       at org.apache.derby.impl.sql.execute.NormalizeResultSet.normalizeColumn(Unknown Source)
       at org.apache.derby.impl.sql.execute.NormalizeResultSet.normalizeRow(Unknown Source)
       at org.apache.derby.impl.sql.execute.NormalizeResultSet.getNextRowCore(Unknown Source)
       at org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(Unknown Source)
       at org.apache.derby.impl.sql.execute.InsertResultSet.getNextRowCore(Unknown Source)
       at org.apache.derby.impl.sql.execute.InsertResultSet.open(Unknown Source)
       at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
       at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
       ... 5 more

D:\JavaDevelopment\Testing\DataBase\db-derby-10.14.2.0-bin>MORE

 
Mike Savvy
Rancher
Posts: 127
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Here is the console I get when I run the code:


I do not know why you have this SQLDataException. I have no problem with it
Untitled.png
[Thumbnail for Untitled.png]
 
Mike Savvy
Rancher
Posts: 127
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay I have got the same Exception as Norm Radder  
I found derby.jar in an archive from apache website
 
Norm Radder
Master Rancher
Posts: 4068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

//  Derby supports the following formats for TIMESTAMP:       yyyy-mm-dd hh:mm:ss[.nnnnnn]


Works when :00 added for the :ss part of the TIMESTAMP
 
Mike Savvy
Rancher
Posts: 127
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding :00 do not help me. I still have the problem. I have tried for 3 times
Untitled.png
[Thumbnail for Untitled.png]
 
Norm Radder
Master Rancher
Posts: 4068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no ideas why you get that error with the correction I suggested.  The only situation I can imagine is there are two copies of the source.  One was updated and the older one was executed.
One suggestion I have is to move all your code out of the  Program Files folder to your own personal folder.  
 
Rancher
Posts: 4775
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How old is that book?
Derby was removed from the JDK over 5 years ago.

As Norm says, do not do your development in the JDK folders.
Do them in your own user folders somewhere.
You should have no need to mess with the JDK itself.
 
Mike Savvy
Rancher
Posts: 127
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys for information. The book is from 2016, I bought it last year
 
bacon. tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic