0

Hi over there,

is it possible to execute several SQL Statements with one(!) command?

For example something like that:

Statement s = con.createStatement();
sql=
"CREATE DATABASE MeineDb+
SHOW databases+
USE MeineDb+
CREATE TABLE MeineTestTabelle ( i INT, c CHAR(3), s VARCHAR(8), dt DATE )+
CREATE TABLE MeineAdressen ( Name VARCHAR(16), Plz INT, Ort VARCHAR(16) )+
SHOW tables+
INSERT INTO MeineTestTabelle VALUES ( 11, 'ABC', 'Blubb', '2000-01-01' )+
INSERT INTO MeineTestTabelle VALUES ( 12, 'ab', 'Blabla', '2000-12-31' )+
INSERT INTO MeineTestTabelle VALUES ( 42, 'xy', 'äöüߧ€', '2005-06-06' )+
SELECT * FROM MeineTestTabelle+
INSERT INTO MeineAdressen VALUES ( 'Achim',     52078, 'Aachen' )+
INSERT INTO MeineAdressen VALUES ( 'Alexander', 52134, 'Herzogenrath' )+
INSERT INTO MeineAdressen VALUES ( 'Helmut',    52066, 'Aachen' )+
INSERT INTO MeineAdressen VALUES ( 'Josef',     52070, 'Aachen' )+
INSERT INTO MeineAdressen VALUES ( 'Manfred',   52146, 'Würselen' )+
INSERT INTO MeineAdressen VALUES ( 'Patrick',   52074, 'Aachen' )+
INSERT INTO MeineAdressen VALUES ( 'Roland',    52134, 'Herzogenrath' )+
INSERT INTO MeineAdressen VALUES ( 'Torsten',   52072, 'Aachen' )+
INSERT INTO MeineAdressen VALUES ( 'Werner',    52066, 'Aachen' )";

s.execute(sql);

In words:
i want to create a database, some tables and some tuples with one command. a kind of installer, if you want.

i tried the above shown code, and some modifications, but it doesn't help..
any chance?


TY

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by kingarthur
Featured Replies
  • 1
    ~s.o.s~ 2,560   7 Years Ago

    Look into the [URL="http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec2/jdbc2.1.frame6.html"]batch execution capabilities[/URL] of JDBC. Read More

0

No, a statement is a single SQL statement. You can batch them into transactions and commit them as a unit if you wish, but each statement still needs to be executed individually. You could write a stored procedure and call it with a CallableStatement if you wanted to go that route.

0

not the answer i wanted to hear ( :D ), but thanks a lot !

//edit:
the batch-thing looks good. ty

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.