Tag,
ich habe folgendes Problem. Ich möchte eine Tabelle befüllen und bekomme einen Syntax-Fehler geliefert. Hier der passende Code:
[Java]protected static void erstelleTabellen(Connection conn)
{
try
{
Statement stmt = conn.createStatement();
/** stmt.execute( "DROP TABLE branches CASCADE;"+
"DROP TABLE accounts CASCADE;"+
"DROP TABLE tellers CASCADE;"+
"DROP TABLE history"); **///besserer SQL-Befehl für Löschen?!
stmt.execute("create table branches "+
"(branchid int not null AUTO_INCREMENT,"+
"branchname char(20) not null,"+
"balance int not null,"+
"address char(72) not null,"+
"primary key (branchid) );");
stmt.execute("create table accounts"+
"(accid int not null AUTO_INCREMENT,"+
"name char(20) not null,"+
"balance int not null,"+
"branchid int not null,"+
"address char(68) not null,"+
"primary key (accid),"+
"foreign key (branchid) references branches);");
stmt.execute("create table tellers"+
"(tellerid int not null AUTO_INCREMENT,"+
"tellername char(20) not null,"+
"balance int not null,"+
"branchid int not null,"+
"address char(68) not null,"+
"primary key (tellerid),"+
"foreign key (branchid) references branches);");
stmt.execute("create table history"+
"(accid int not null AUTO_INCREMENT,"+
"tellerid int not null,"+
"delta int not null,"+
"branchid int not null,"+
"accbalance int not null,"+
"cmmnt char(30) not null,"+
"foreign key (accid) references accounts,"+
"foreign key (tellerid) references tellers,"+
"foreign key (branchid) references branches );");
}
catch(SQLException e)
{
System.err.println(e);
System.exit(1);
}
} // ende Methode erstelleTabellen.
} // ende Klasse Initialisierung.[/Java]
Fehlermeldung:
ich habe folgendes Problem. Ich möchte eine Tabelle befüllen und bekomme einen Syntax-Fehler geliefert. Hier der passende Code:
[Java]protected static void erstelleTabellen(Connection conn)
{
try
{
Statement stmt = conn.createStatement();
/** stmt.execute( "DROP TABLE branches CASCADE;"+
"DROP TABLE accounts CASCADE;"+
"DROP TABLE tellers CASCADE;"+
"DROP TABLE history"); **///besserer SQL-Befehl für Löschen?!
stmt.execute("create table branches "+
"(branchid int not null AUTO_INCREMENT,"+
"branchname char(20) not null,"+
"balance int not null,"+
"address char(72) not null,"+
"primary key (branchid) );");
stmt.execute("create table accounts"+
"(accid int not null AUTO_INCREMENT,"+
"name char(20) not null,"+
"balance int not null,"+
"branchid int not null,"+
"address char(68) not null,"+
"primary key (accid),"+
"foreign key (branchid) references branches);");
stmt.execute("create table tellers"+
"(tellerid int not null AUTO_INCREMENT,"+
"tellername char(20) not null,"+
"balance int not null,"+
"branchid int not null,"+
"address char(68) not null,"+
"primary key (tellerid),"+
"foreign key (branchid) references branches);");
stmt.execute("create table history"+
"(accid int not null AUTO_INCREMENT,"+
"tellerid int not null,"+
"delta int not null,"+
"branchid int not null,"+
"accbalance int not null,"+
"cmmnt char(30) not null,"+
"foreign key (accid) references accounts,"+
"foreign key (tellerid) references tellers,"+
"foreign key (branchid) references branches );");
}
catch(SQLException e)
{
System.err.println(e);
System.exit(1);
}
} // ende Methode erstelleTabellen.
} // ende Klasse Initialisierung.[/Java]
Fehlermeldung:
Java:
org.postgresql.util.PSQLException: FEHLER: Syntaxfehler bei „AUTO_INCREMENT“
Position: 46[/Java]
Zuletzt bearbeitet: