Mike London wrote:I'm not sure what this means since I haven't yet created fields in the target DB. That's part of the job of this code - which worked fine on two other tables already. (confusing)
Claude Moore wrote:May you post an excerpt of you code, with more details? Generally speaking the error you encountered means that a parameter in the statement hasn't been set. If you have X '?' placeholders, you need to set X values as well. What sounds strange to me is that you are talking about a ResultSet:where did you obtained this from? by executing the statement? I don't think so, because if the statement is not properly prepared -I.e you missed to set any params - you should not be able to get any ResultSet..
Claude Moore wrote:How many columns has your table? Try with INSERT INTO TABLENAME (COLUMN1, COLUMN2,...,COLUMNx) VALUES (?,?,...,?) syntax. If I am not wrong, the number of columns inserted must match values specified... Not sure of this, though.
Paul Clapham wrote:
Mike London wrote:I'm not sure what this means since I haven't yet created fields in the target DB. That's part of the job of this code - which worked fine on two other tables already. (confusing)
I found that confusing too. If I read it straight it suggests that you expect that preparing an INSERT statement will cause a CREATE TABLE or ALTER TABLE statement to be run, thereby creating columns in the table. But that doesn't make sense to me because the INSERT statement doesn't provide column names and column types. And like Claude I was confused by the reference to ResultSet, especially if it was supposed to be getting data from a table which didn't have columns declared yet.
But maybe "this code" refers to a larger piece of code, from which you only posted one line. And maybe something else in that larger piece of code was where the table and its columns were being declared. And maybe it didn't do what you expected it to do.
Or maybe "I haven't yet created fields" just means "I haven't added any rows" and I'm following a red herring?
Claude Moore wrote:Are you sure that the source and destination tables are equivalent, with the very same columns, column types and so on? About INSERT INTO TABLE, I checked the syntax and you have to specify columns names if you are inserting only a subset of columns. For example, if you have a table with 3 columns you cannot run a INSERT INTO MYTABLE VALUES (?,?), so I would check that second table has the very same column number.
Claude Moore wrote:Would it be a problem posting the fetch - and - insert cycle code snippet?
Claude Moore wrote:OK, sorry for asking that in this case. Let us know, the whole thing is intriguing
Mike London wrote:I'll modify the code that creates the INSERT statement tomorrow when I'm fresh and post back.
Roel De Nijs wrote:
Mike London wrote:I'll modify the code that creates the INSERT statement tomorrow when I'm fresh and post back.
If for some reason the ALTER TABLE statement for one of the columns failed, you'll probably get another runtime exception when trying to create the prepared statement: "unknown column name" (or something similar).
Mike London wrote:It's all done now.
Roel De Nijs wrote:
Mike London wrote:It's all done now.
Glad to hear you solved your issue! And thanks for coming back and sharing your solution. That might be helpful for other ranchers as well. Have a cow!
Claude Moore wrote:More or less, a cow is a very very nice way to tell you that you posted something useful or interesting here at the ranch. Only Ranchers and higher rank members may award cows. For more information, have a look at the FAQ or wiki section.
By the way, this cow is IMHO fully deserved. I am in doubt that your case may be usefull to others -maybe too much specific case - but it is really a nice behavior to give a feedback after having asked for help !
Mike London wrote:BTW, what do the cows mean?
Mike London wrote:If I get 10 cows is the 11'th one free? ;)
Mike London wrote:Interesting. I've been on the ranch since 2002 and only have three cows? I must be getting better!
Mike London wrote:Oh, BTW, ALTER TABLE wasn't the best approach after all. It turns out that the destination database I was using allows you to create a table independently of the fields-very unusual.
In any case, I switched to a CREATE TABLE and that works better and is more cross-platform.
Roel De Nijs wrote:
Mike London wrote:Interesting. I've been on the ranch since 2002 and only have three cows? I must be getting better!
Don't be too hard for yourself! The majority of your time here at CodeRanch was "cowless", the cows were only introduced 3 years ago.
Mike London wrote:Oh, BTW, ALTER TABLE wasn't the best approach after all. It turns out that the destination database I was using allows you to create a table independently of the fields-very unusual.
In any case, I switched to a CREATE TABLE and that works better and is more cross-platform.
Executing one CREATE TABLE statement instead of executing +80 ALTER TABLE statements makes indeed more sense and is a nice improvement Just curious: which (source and) destination database are you using?
Mike London wrote:Nope, in a SQL INSERT, you don't have to list all the field names. Just the VALUES(....) is fine as long as the rest of the syntax is OK.
Mike London wrote:The destination database on alter table insert coluumn forces TimeStamps to be Always Validated. Since that destination DB doesn't accept standard dates (2016-11-01 11:11:05), I had to write a quick data formatter:
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|