user2891462
user2891462

Reputation: 3333

Create VARCHAR FOR BIT DATA column

I am trying to create a SQL table in Netbeans 8.0 with one of its columns meant to store a byte[] (so VARBINARY is the type I am looking for). The wizard for the creation of a new table offers me the option of VARCHAR FOR BIT DATA, which should work, but it raises a syntax error when creating the table:

    create table "BANK".Accounts
    (
    id NUMERIC not null,
    pin VARCHAR FOR BIT DATA not null,
    primary key(id)
    )

The error is due to the presence of the word FOR, so I manually change the statement so that it is

    create table "BANK".Accounts
    (
    id NUMERIC not null,
    pin "VARCHAR FOR BIT DATA" not null,
    primary key(id)
    )

but now the problem is that the type does not exist. Any ideas?

Thank you.

Upvotes: 1

Views: 2649

Answers (1)

Bryan Pendleton
Bryan Pendleton

Reputation: 16359

Here's the manual page for VARCHAR FOR BIT DATA: http://db.apache.org/derby/docs/10.10/ref/rrefsqlj32714.html

Note the section that says:

Unlike the case for the CHAR FOR BIT DATA type, there is no default length for a VARCHAR FOR BIT DATA type. The maximum size of the length value is 32,672 bytes.

So the problem is that you haven't specified a length.

If your byte array is, say, 256 bytes long, you could specify

pin VARCHAR (256) FOR BIT DATA NOT NULL,

You might also consider using BLOB if that fits your requirements. You can see all the Derby data types here: http://db.apache.org/derby/docs/10.10/ref/crefsqlj31068.html

Upvotes: 1

Related Questions