• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

create tables using java code by fetching from .sql file

 
Sashidhar Rao Gopisetty
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have to prepare a javcode which creates tables by accepting sql file name.
connection to DB will be established by properties file.it will be gernalised so that any DB can be connected which specify in properties and any statement can be executed given in sql file.
please it is urgent.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the problem??
 
Sashidhar Rao Gopisetty
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a problem to fetch sql file in the java file
 
Sashidhar Rao Gopisetty
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i mean to say that i dont know how to create tables by fetching from sql file name as a parameter to the java function which will execute.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
377
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sashidhar,
That's still pretty broad. Which of the following are you having trouble with?

1) Reading a file to get a name
2) Creating a table in SQL
3) Making a JDBC call
 
Sashidhar Rao Gopisetty
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to write a java code in which i have to call a function to create sql tables and insert data into those table at once.

1.connection established by the code using properties file. (its done)
2.create tables and insert data ito tables script is prepared and store ina x.sql file.(executed and tested.its done)
3.now i have to call the file x.sql file in the code and execute the script in that file at once, in the function i will take two parameters one properties file name two sql file name.(this is what i dont know)
please send me any code snippet matching this requirement
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If sounds like your problem is File I/O, not SQL. Your problem is reading the file, yes?

Take a look at the java.io.File class and its related classes - java.io.FileInputStream (or java.io.FileReader) is what you probably want to use in this case.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
377
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sashidhar Rao Gopisetty:
now i have to call the file x.sql file in the code and execute the script in that file at once, in the function i will take two parameters one properties file name two sql file name.(this is what i dont know)
please send me any code snippet matching this requirement

I agree with Joel that this is an I/O question, so I am moving it to our I/O forum.

For some examples of how to read a file, take a look at Sun's

I/O tutorial.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic