• Post Reply Bookmark Topic Watch Topic
  • New Topic

Execute queries  RSS feed

 
Nathalie Monvoisin
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi readers !
I have a file containing a number of sql statement. i want my java application to read content of the file and that each statement is executed from this java app.
i know how to read each line of the file, but how to make it execute each queries??
How can i do that??
I'm using postgresql
Thank you.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you will have to divide and rule. Maybe we shall start with reading each line of the file: do you know how to do that?

Leave everything else till later.
 
Nathalie Monvoisin
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I know how to read in a file line by line
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you can now display each SQL query in turn?
 
Nathalie Monvoisin
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should I store each line in a variable fist then send it for execution?
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know how to read each line of the file, but how to make it execute each queries??

You will be using JDBC to do that.

Should I store each line in a variable fist then send it for execution?

How you store the SQL lines depends on how you are going to use them. If there's only a few (say less then five) SQL statements, then maybe storing them in separate, well-named variables makes sense. If you're going to execute all the statements one after another, an array or ArrayList should work fine.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!