Write to database

Here's my database table:
Column Name      Data Type  
Artikel                  nvarchar(50)
ID                         int
Namn                   nvarchar(50)
Pris                      float
ISBN                    nvarchar(50)

Why do I get this error?
ALLVARLIG: null
com.microsoft.sqlserver.jdbc.SQLServerException: The name "namn" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
        at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
public void Write(int ID, String namn, float pris, String isbn)  {
        try {
            m_Statement = con.createStatement();
        }
        catch (SQLException ex) {
            Logger.getLogger(MysqlConnect.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            m_Statement.executeUpdate("INSERT INTO BokTabell " + "VALUES ('Bok'," +ID +",namn," +pris +",'isbn'");
        }
        catch (SQLException ex) {
            Logger.getLogger(MysqlConnect.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

Open in new window

MickeysAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:
namn should be in single quotes
0
for_yanCommented:
INSERT INTO BokTabell " + "VALUES ('Bok'," +ID +",'" + namn + "'," +pris +",'" + isbn+ "'");

Open in new window

0
for_yanCommented:

corrected :
"INSERT INTO BokTabell " + "VALUES ('Bok'," +ID +",'" + namn + "'," +pris +",'" + isbn+ "')");

Open in new window

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

MickeysAuthor Commented:
I wrote "heey" on Namn and get this error now:
com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'He'.
0
for_yanCommented:
Did you use my latest variant:
"INSERT INTO BokTabell " + "VALUES ('Bok'," +ID +",'" + namn + "'," +pris +",'" + isbn+ "')");

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
for_yanCommented:
Good parctice to do that:
System.out.println("INSERT INTO BokTabell " + "VALUES ('Bok'," +ID +",'" + namn + "'," +pris +",'" + isbn+ "')");
 m_Statement.executeUpdate("INSERT INTO BokTabell " + "VALUES ('Bok'," +ID +",'" + namn + "'," +pris +",'" + isbn+ "')");

Open in new window


and make sure to put System.out.println before executeUpdate and just cuut and paste the string

Thwen if it does not work - you at least will imeediately see the string and spot the error
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.