This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Auto Format data for Insert into...?

 
Z Zia
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

My application read log files in which each line = record of table. Field separator in log files is pipe sign, so data is something like this:

String Field 1 | Integer Field 1 | Date Field 1 | String Field 2......

When I transform this into "Insert into..." statement I have make my SQL like this:

Insert into abc values('String Field 1',Integer Field 1,'Date Field 1'...)

Question) I dont wish to enter '' for text or date fields, i.e, how can I enter data without knowing the type of respective coulmn in table, any way?

Regards,
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a stored procedure send all the parameters to it & execute the sp.
Srini
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the API for PreparedStatements. OK you can't use them to "enter data without knowing the type of respective coulmn in table, any way", but then that's not something you can do with databases anyway. PreparedStatements will remove your need to use quotes.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:
Read the API for PreparedStatements. OK you can't use them to "enter data without knowing the type of respective coulmn in table, any way", but then that's not something you can do with databases anyway. PreparedStatements will remove your need to use quotes.


Yes it's also a good solution ..
Srini
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while using prepared statement you have to do something like this.

ps.setString();
ps.setInt();
ps.setDate();

so, here i have something in my mind but i think not really a optimized solution. you can query that table with "*". and then use the getMetaData() to know the column types, then execute your insert.

how it sounds?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic