[Logo]
Forums Register Login
create tables using java code by fetching from .sql file
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.
Where is the problem??
i have a problem to fetch sql file in the java file
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.
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
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
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.
 
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.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Nov 23, 2017 00:57:44.