Обсуждение: JDBC using REFERENCES

Поиск
Список
Период
Сортировка

JDBC using REFERENCES

От
Arbol One
Дата:

In an application that uses JDBC I am trying to use the following statement

               // Table parameters
                var sql = new MyString();
                sql.setData("CREATE TABLE IF NOT EXISTS ");
                sql.append(this.tableName);
                sql.append(" (");
                sql.append("index SERIAL NOT NULL, ");
                sql.append("id TEXT PRIMARY KEY, ");
                sql.append("day TEXT NOT NULL, ");
                sql.append("month TEXT NOT NULL, ");
                sql.append("year TEXT NOT NULL, ");
                sql.append("hour TEXT NOT NULL, ");
                sql.append("minute TEXT NOT NULL, ");
                sql.append("second TEXT NOT NULL, ");
                sql.append("millisecond TEXT NOT NULL, ");
                sql.append("am_pm TEXT NOT NULL, ");
                sql.append("admin boolean NOT NULL DEFAULT false, ");
                sql.append("CONSTRAIN id PRIMARY KEY (id)");
<== Error
                sql.append(");");

but I get a message saying :

Exception in thread "main" java.sql.SQLException: In company.contact.createTable()
ERROR: syntax error at or near "("
  Position: 315

Does JDBC allow us to do this?
What am I doing wrong?
How to fix this

--
ArbolOne ™
Using Fire Fox and Thunderbird.
ArbolOne is composed of students and volunteers dedicated to providing free services to charitable organizations.
ArbolOne's development on Java, PostgreSQL, HTML and Jakarta EE is in progress [ í ]

Re: JDBC using REFERENCES

От
"David G. Johnston"
Дата:
On Sunday, November 24, 2024, Arbol One <ArbolOne@hotmail.ca> wrote:


                sql.append("CONSTRAIN id PRIMARY KEY (id)"); <== Error
                          


The word constraint ends with a “T”

David J.

Re: JDBC using REFERENCES

От
Rob Sargent
Дата:


On Nov 24, 2024, at 7:15 PM, Arbol One <ArbolOne@hotmail.ca> wrote:



In an application that uses JDBC I am trying to use the following statement

               // Table parameters
                var sql = new MyString();
                sql.setData("CREATE TABLE IF NOT EXISTS ");
                sql.append(this.tableName);
                sql.append(" (");
                sql.append("index SERIAL NOT NULL, ");
                sql.append("id TEXT PRIMARY KEY, ");
                sql.append("day TEXT NOT NULL, ");
                sql.append("month TEXT NOT NULL, ");
                sql.append("year TEXT NOT NULL, ");
                sql.append("hour TEXT NOT NULL, ");
                sql.append("minute TEXT NOT NULL, ");
                sql.append("second TEXT NOT NULL, ");
                sql.append("millisecond TEXT NOT NULL, ");
                sql.append("am_pm TEXT NOT NULL, ");
                sql.append("admin boolean NOT NULL DEFAULT false, ");
                sql.append("CONSTRAIN id PRIMARY KEY (id)");
<== Error
                sql.append(");");

but I get a message saying :


Exception in thread "main" java.sql.SQLException: In company.contact.createTable()
ERROR: syntax error at or near "("
  Position: 315


 Collapse all the append()s after rable e and see if parentheses are balanced.
Does JDBC allow us to do this?
What am I doing wrong?
How to fix this

--
ArbolOne ™
Using Fire Fox and Thunderbird.
ArbolOne is composed of students and volunteers dedicated to providing free services to charitable organizations.
ArbolOne's development on Java, PostgreSQL, HTML and Jakarta EE is in progress [ í ]

Re: JDBC using REFERENCES

От
"David G. Johnston"
Дата:
On Sunday, November 24, 2024, Arbol One <ArbolOne@hotmail.ca> wrote:


                sql.append("index SERIAL NOT NULL, ");
                sql.append("id TEXT PRIMARY KEY, ");

                sql.append("CONSTRAIN id PRIMARY KEY (id)");
<== Error
                         


This is quite confusing, having the index column be serial but not PK (or even unique…) while the id column is the PK, which you’ve redundantly specified.

David J.