3
votes
private Connection conn = DriverManager.getConnection(URL, info);
try {
String sql = "INSERT INTO \"STUD1582251\".\"ACCOUNTS\" VALUES USERNAME=?, PASSWORD=?, PORTFOLIONAME=?";
    PreparedStatement stm = conn.prepareStatement(sql);
    stm.setString(1, user.getUsername());
    stm.setString(2, user.getPassword());
    stm.setString(3, user.getPortfolioName());
    System.out.println(sql);
    stm.executeUpdate();
} catch (SQLException e) {
    e.printStackTrace();
}

Exception

SELECT username FROM "STUD1582251"."ACCOUNTS" WHERE username=? INSERT INTO "STUD1582251"."ACCOUNTS" VALUES USERNAME=?, PASSWORD=?, PORTFOLIONAME=? java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended

1
Posting the error stacktrace might help... - Tomer
You know that you don't need the double quotes around column and table names? - a_horse_with_no_name
There's a SELECT as well as a malformed INSERT statement concatenated together. Check how you're creating the SQL string. - Jesper

1 Answers

7
votes

INSERT SQL statement must be:

 String sql = "INSERT INTO \"STUD1582251\".\"ACCOUNTS\" (USERNAME,PASSWORD,PORTFOLIONAME) VALUES (?,?,?)";

PS: Use " (double quotes) around identifier if it is a reserved word.