I have an issue where I am trying to insert 3 values into a table in a local postgres database.
I have this code that deals with the sql here:
try {
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/javadb","postgres", "mypass");
stmt = c.createStatement();
String sql = "CREATE TABLE GAMES " +
"(GAME_NAME TEXT PRIMARY KEY NOT NULL, " +
" PRICE FLOAT NOT NULL, " +
" URL CHAR(800))";
String sql2 = "INSERT INTO GAMES (GAME_NAME, PRICE, URL) "
+ "VALUES (" + this.GAME_NAME + ", " +
Float.toString(this.PRICE) + ", " +
this.URL + ");";
stmt.executeUpdate(sql);
stmt.executeUpdate(sql2);
stmt.close();
} catch (Exception e) {
e.printStackTrace();
}
And the Constructor here:
public class UploadToDB {
String GAME_NAME, URL;
float PRICE;
public UploadToDB(String GAME_NAME, float PRICE, String URL) {
this.GAME_NAME = GAME_NAME;
this.PRICE = PRICE;
this.URL = URL;
}
}
When I run this code, I get this error:
org.postgresql.util.PSQLException: ERROR: column "cod" does not exist
I assume this means it is trying to insert something into a column named after the values.
How can I run this so that it actually inserts the values given into the columns?