Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Save URL's in a table in a Derby database.  RSS feed

 
Kirill Varivoda
Greenhorn
Posts: 20
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Guys, I want to save URL's in a table in a Derby database.

I'm using embedded derby in this code.
This is it:



Main Sql statement from above code:
"create table SITES(page varchar(2083), inner varchar(2083), external varchar(2083))"

But I got an error:


Maybe there is some other way?

My goal is to create page_URL and put INNER and EXTERNAL URL's associated with page_URL from my Java program to this table.
For example:
Column1: Main page URL.
Column2: inner URL's ,
Column3: external_URL's.
and so on for another URL.

I'm new to this.
 
Paul Clapham
Sheriff
Posts: 22203
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would help if you posted both the error message and the code which caused the error message. As it stands now, we have to click on a link to an external site to find out that neither of those two are available. Post them both here, that would be easier both for you and for anybody interested in helping.
 
Kirill Varivoda
Greenhorn
Posts: 20
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:It would help if you posted both the error message and the code which caused the error message. As it stands now, we have to click on a link to an external site to find out that neither of those two are available. Post them both here, that would be easier both for you and for anybody interested in helping.


Ok, I've changed my post.
 
Ron McLeod
Saloon Keeper
Posts: 1456
209
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your database table is probably not getting created because inner is a reserved word - if you want to use it as a column name, you will need to enclose it in back-ticks.

stmt.execute("create table " + tableName + "(page varchar(2083), `inner` varchar(2083), external varchar(2083))");
 
Kirill Varivoda
Greenhorn
Posts: 20
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:Your database table is probably not getting created because inner is a reserved word - if you want to use it as a column name, you will need to enclose it in back-ticks.

stmt.execute("create table " + tableName + "(page varchar(2083), `inner` varchar(2083), external varchar(2083))");


Thanks for this, I changed a line



but now I got a new error.

 
Ron McLeod
Saloon Keeper
Posts: 1456
209
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at this line and pay attention to the how you are quoting the string values:

stmt.execute("insert into " + tableName + " values (" + page + ",'" + inner + "','" + external + "')");
 
Dave Tolls
Ranch Hand
Posts: 2554
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:Take a look at this line and pay attention to the how you are quoting the string values:

stmt.execute("insert into " + tableName + " values (" + page + ",'" + inner + "','" + external + "')");


And then use a PreparedStatement...
 
Kirill Varivoda
Greenhorn
Posts: 20
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:Take a look at this line and pay attention to the how you are quoting the string values:

stmt.execute("insert into " + tableName + " values (" + page + ",'" + inner + "','" + external + "')");


Thank you! I've found a mistake:
stmt.execute("insert into " + tableName + " values ('" + page + "','" + inner + "','" + external + "')");
 
Kirill Varivoda
Greenhorn
Posts: 20
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:
Ron McLeod wrote:Take a look at this line and pay attention to the how you are quoting the string values:

stmt.execute("insert into " + tableName + " values (" + page + ",'" + inner + "','" + external + "')");


And then use a PreparedStatement...


Ok! I study what you've send. Thank you.
 
Campbell Ritchie
Sheriff
Posts: 54034
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this would fit better in our databases forum: moving.

Why have you got so many static methods?
 
Kirill Varivoda
Greenhorn
Posts: 20
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I think this would fit better in our databases forum: moving.

Why have you got so many static methods?


Ok. I don't know actually. Big part of this code was found on internet, I just use it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!