Avatar of Mickeys
Mickeys
Flag for Sweden

asked on 

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

Java

Avatar of undefined
Last Comment
for_yan

8/22/2022 - Mon