This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Auto Format data for Insert into...? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Auto Format data for Insert into...?" Watch "Auto Format data for Insert into...?" New topic
Author

Auto Format data for Insert into...?

Z Zia
Greenhorn

Joined: Oct 03, 2004
Posts: 24
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

Joined: Sep 28, 2004
Posts: 1228
Use a stored procedure send all the parameters to it & execute the sp.
Srini


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
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

Joined: Aug 15, 2004
Posts: 2874
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Auto Format data for Insert into...?
 
Similar Threads
parsing in servlet
truncation errors storing a Date in MySQL table
Insert a Date into DB JDBC
Converting String to Date???
Auto Format insert into....?