0
               // Attempt to get 1 transaction
                String sqlQuery = "INSERT INTO '" + this.crawlPageTableName
                        + "' (url, status) VALUES (?, 'added')";

                PreparedStatement prest = connect.prepareStatement(sqlQuery);
                prest.setString(1, this.url);
                
                System.out.println("Querying with: " + sqlQuery);

                // Result set get the result of the SQL query
                this.resultSet = prest.executeQuery();
                

I am really not getting what I am doing wrong here to get this error.

The output of printline is

Querying with: INSERT INTO 'crawlPage' (url, status) VALUES (?, 'added')


java.sql.SQLSyntaxErrorException: (conn=1877278) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''crawlPage' (url, status) VALUES ('

I am really lost here as the same query from the printline works directly on the MariaDB server through phpMyAdmin.

Vish
  • 4,508
  • 10
  • 42
  • 74
  • 1
    If table names need to be escaped, they should be enclosed in backticks `\``, not single quotes. – Nick Feb 06 '21 at 05:55

1 Answers1

2

I believe you shouldn't have any single quotes wrapping the table name:

String sqlQuery = "INSERT INTO " + this.crawlPageTableName
                        + " (url, status) VALUES (?, 'added')";
Neo
  • 779
  • 5
  • 13