#SQL alter table with parameter doesn't work

7 messages · Page 1 of 1 (latest)

spiral wadi
#

Hi! I have the following query,


  ALTER TABLE 
    fishing_player_data 
  ADD 
    COLUMN ? INT NOT NULL DEFAULT 0;

I then do statement.setString(1, "goldfish_fishes_caught")
I print it before doing statement.executeUpdate:

ALTER TABLE 
fishing_player_data 
  ADD 
  COLUMN 'goldfish_fishes_caught' INT NOT NULL DEFAULT 0;

However, I'm getting this error:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''goldfish_fishes_caught' INT NOT NULL DEFAULT 0' at line 4"
Any help would be appreciated

granite obsidianBOT
#

This post has been reserved for your question.

Hey @spiral wadi! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

supple lynx
#

You can't pass columns as parameters.

spiral wadi
#

Is there an alternative way of doing it?

#

to prevent sql injection

supple lynx
#

I don't know what kind of problem you're tackling here. Adding columns programatically is usually a very bad idea.