File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes create tables using java code by fetching from .sql file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "create tables using java code by fetching from .sql file" Watch "create tables using java code by fetching from .sql file" New topic
Author

create tables using java code by fetching from .sql file

Sashidhar Rao Gopisetty
Greenhorn

Joined: Sep 23, 2005
Posts: 19
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.


�Don't limit your challenges - challenge your limits.�<br /> <br />Thanks & Regards<br />GDS Sashidhar Rao
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Where is the problem??
Sashidhar Rao Gopisetty
Greenhorn

Joined: Sep 23, 2005
Posts: 19
i have a problem to fetch sql file in the java file
Sashidhar Rao Gopisetty
Greenhorn

Joined: Sep 23, 2005
Posts: 19
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30502
    
150

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


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Sashidhar Rao Gopisetty
Greenhorn

Joined: Sep 23, 2005
Posts: 19
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

Joined: Aug 20, 2001
Posts: 1817

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.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30502
    
150

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: create tables using java code by fetching from .sql file