• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating a database

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to Java.My Question is I want to create a database instead of querrying a database. What I want to do is I have a list of create statements in a text file Is there anyway by which I can connect to database server and execute these create table statements in my text file.
Example
Database.txt is my file and I have
create table entity {
char Name[3];
int SSN[10];
}
create table ChildEntity {
char childname[4];
}
as the content of txt file
 
chandana kotamraju
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still waiting for Java Database Guru's to help me.Thanks in advance any suggestion is wellcome including books or sites to refer.I need a start.
[This message has been edited by chandana kotamraju (edited July 15, 2001).]
 
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming that your DDL statements are in correct syntax.
You will have to read the database text file and parse it into strings which represent indivual SQL statements.
Store them into an array of Strings.

Now establish a database connection in your program.
[CODE]
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc dbc armeet", "sa", "");
Statement stmt = con.createStatement();
for(int i =0; i<=tableStatements.length; i++)
{
stmt.executeUpdate(s[i]);
}
[CODE]
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The easiest thing to do is if your database support batch mode operations.
With MySQL, for example (which is free for download) u can simple write this at the prompt:
mysql -h yourhost -u userid -p < your.txt.file
Enter password; ****
If you need to do this directly from ur java app, the easiest you solution is to spawn a new shell with the this argument:
mysql -h yourhost -u userid -pYoUrPaSsWoRd < your.txt.file
Salam
 
chandana kotamraju
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I appreciate for trying to help me.I will work on this and inform new developments or any interesting problems.Thank you once again.
Chandanakrishna
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic