Обсуждение: Multiple SQL statements in a java program for postgresql DB

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

Multiple SQL statements in a java program for postgresql DB

От
"suhail sarwar"
Дата:
Hi,

I have a java program that interfaces with a postgresql database and need to know how to insert more than 1 sql
statementin the program. The second sql statement always gets ignored for some reason. I have inclded some of the code
below:

db = DriverManager.getConnection(url, "icm00sg", "");

PreparedStatement st = db.prepareStatement("CREATE TABLE Test1 " +
    "(CUS_NO INTEGER, NAME VARCHAR(30), AGE INTEGER, " +
    "STREETNAME VARCHAR(30), STREETNO INTEGER)");

ResultSet rs = st.executeQuery();

PreparedStatement stt = db.prepareStatement("INSERT INTO Test1 " +
    "VALUES (100, 'yahoo', 23, 'donald', 236)");

stt.executeUpdate();

The first statement to create the table always works but the second statement to insert values does not. It does not
matterwhether the second statement creates another table or prints one out, it just won't work. 

Does anyone have any ideas.

Any help much appreciated.

Sarwar