-1

I have the same error as this one : "column not allowed here" error in INSERT statement .

My SQL table's structure looks like this:

CREATE TABLE login
(
    login_id INTEGER PRIMARY KEY,
    username varchar(150) NOT NULL,
    password varchar(150) NOT NULL
);

INSERT INTO login (login_id, username, password) 
VALUES ('9', 'Mukov', '1884');
INSERT INTO login (login_id, username, password) 
VALUES ('10', 'Mukre', '661');

Have I done something wrong?

Edit: even with that way it doesn't work

CREATE TABLE login
(
    login_id INTEGER PRIMARY KEY,
    username varchar(150) NOT NULL,
    password varchar(150) NOT NULL
);

BEGIN
    INSERT INTO login (username, password)
    VALUES ('1', 'Sukre', '1234');
    INSERT INTO login (username, password) 
    VALUES ('2', 'Pal', '123444');
END;
ek.Nik
  • 185
  • 1
  • 8
  • Just start with `BEGIN` and end with `END;/` for the INSERT statements. – Barbaros Özhan Nov 20 '21 at 14:03
  • 1
    Also, don't put quotes round the login_id values as they are integers – NickW Nov 20 '21 at 14:06
  • moment I go check this – ek.Nik Nov 20 '21 at 14:06
  • @NickW Also, don't put quotes round the login_id values as they are integers I didn't get this – ek.Nik Nov 20 '21 at 14:07
  • It means they're redundant(doesn't matter whether you put or do no put) – Barbaros Özhan Nov 20 '21 at 14:08
  • 1
    I got it :) thanks a lot – ek.Nik Nov 20 '21 at 14:10
  • CREATE TABLE login( login_id INTEGER PRIMARY KEY, username varchar(150) NOT NULL, password varchar(150) NOT NULL ); begin INSERT INTO login(username , password )VALUES ('1','Sukre','1234'); INSERT INTO login(username , password ) VALUES ('2','Pal','123444'); end; – ek.Nik Nov 20 '21 at 14:22
  • still not working ...... – ek.Nik Nov 20 '21 at 14:23
  • 1
    check [this](https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=e8c7cf387a4526f2a1e79642a6e0371c) out. What's your IDE by the way? – Barbaros Özhan Nov 20 '21 at 14:31
  • @BarbarosÖzhan still not working – ek.Nik Nov 20 '21 at 14:37
  • @BarbarosÖzhan the Netbeans 8.2 – ek.Nik Nov 20 '21 at 14:37
  • It's important how you invoke from that framework. Why do you need the DDL(create table statement, I suppose it's already created from an IDE)? Suppose that you might encounter problem of issuing DDL and DML from the same code block. – Barbaros Özhan Nov 20 '21 at 14:40
  • I create the create table statement in the oracle. I am trying to insert data from jTextField1 ,jTextField2 ,jTextField3 from java swing (netbeans) into the oracle .I press run file on JFrame. It runs.I write in the jTextfields and I press the button. – ek.Nik Nov 20 '21 at 14:46
  • Seems you need to use a SQL Insert statement string with bind variables – Barbaros Özhan Nov 20 '21 at 14:50
  • If I got it right you mean this that I have in Netbeans : statement.executeUpdate("INSERT INTO LOGIN VALUES(" + jTextField1.getText() + ",'" + jTextField2.getText() + "'," + jTextField3.getText() + ")"); – ek.Nik Nov 20 '21 at 14:52
  • Yes, but do not use string concatenation which make your query vulnerable to injection, rather bind variables. – Barbaros Özhan Nov 20 '21 at 14:54
  • @BarbarosÖzhan Thank you a lot ,but english aint my first language and I can't get what you mean.Could you give me what you mean? – ek.Nik Nov 20 '21 at 14:57
  • you're welcome @m.s . I've meant *prepared statements* for your DML such as documented [here](https://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html). In your current case, you concatenate the subststrings with an operator(`+` indeed it, which should be pipe[`|`], is wrong too). Have a nice study! – Barbaros Özhan Nov 20 '21 at 15:05
  • This works in Oracle, which means that your problem must be with whatever tool and/or code you are using to execute these commands. – RBarryYoung Nov 20 '21 at 15:08

1 Answers1

0

Update your insert statement as -

BEGIN
    INSERT INTO login(login_id, username , password )VALUES (1,'Sukre','1234');
    INSERT INTO login(login_id, username , password ) VALUES (2,'Pal','123444');
END;
/
Ankit Bajpai
  • 13,128
  • 4
  • 25
  • 40