How can I create the table in database using Java/JDBC?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   parag_dharmadhikari
Posted On:   Thursday, August 1, 2002 03:36 AM

Hi all



Is it possible to create table in database through interface which will use Java/JDBC. As I think "Create Table" is an SQL statement and hence we can create the table using JDBC. But can pls anybody tell me how exactly I should be doing.



Regards

Parag

Re: How can I create the table in database using Java/JDBC?

Posted By:   Simone_Re  
Posted On:   Thursday, August 1, 2002 05:50 AM

Execute a "Create table" statement is a right way to proceed.

The SQL syntax is something like this:



CREATE TABLE table_name (field1 INT NOT NULL, field2 CHAR(2), field3 DATE);


Possible field type can change from DBMS to DBMS.

This code create a table with only a field in MySQL:

String sql = "CREATE TABLE Servizio (SER varchar(100))";
Statement st = connection.createStatement();
int result = st.executeUpdate(sql);

The integer "result" contains the number of records updated by the statement.
About | Sitemap | Contact