Java MySQL Programming Error

Ne
- in Servers
2

I have a problem who can help me I'm programming a system for my Minecraft server because I use MySQL. Thanks in advance.

Here is the error message:

Here is the code:

package de.freundesgame.mysql;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class SQLStats {

public static boolean playerExist (String uuid) throws SQLException {
PreparedStatement st = new MySQL ("localhost", "Votes", "root", "redlabel22"). GetConnection (). PrepareStatement ("SELECT 'UUID' FROM 'Votestats' WHERE 'UUID' =?");
st.setString (1, uuid);
ResultSet rs = st.executeQuery ();

while (rs.next ()) {
return true;
}
return false;

}

public static void createPlayer (String uuid) {

try {
if (playerExist (uuid)) {
PreparedStatement st = new MySQL ("localhost", "Votes", "root", "redlabel22"). GetConnection (). PrepareStatement ("INSERT INTO 'Votestats' ('UUID', 'VOTECOINS') VALUES (?!)" );
st.setString (1, uuid);
st.setInt (0, 2);
}
} catch (SQLException e) {
// TODO auto-generated catch block
e.printStackTrace ();
}

}

public static Integer getVotes (String uuid) {
Integer i = 0;

try {
if (playerExist (uuid)) {

PreparedStatement st = new MySQL ("localhost", "Votes", "root", "redlabel22"). GetConnection (). PrepareStatement ("SELECT 'VOTECOINS' FROM 'Votestats' WHERE 'UUID' =?");
ResultSet rs = st.executeQuery ();
st.setString (1, uuid);
while (rs.next ()) {
i = rs.getInt ("votecoins");
return i;
}

} else {
createPlayer (uuid);
getVotes (uuid);
}
} catch (SQLException e) {
// TODO auto-generated catch block
e.printStackTrace ();
}
return i;
}

public static void setVotes (String uuid, Integer votes) {

try {
if (playerExist (uuid)) {
PreparedStatement st = new MySQL ("localhost", "Votes", "root", "redlabel22"). GetConnection (). PrepareStatement ("UPDATE 'Votestats' SET 'VOTECOINS' =? WHERE 'UUID' =?");

st.setInt (votes, 1);
st.setString (2, uuid);
} else {
createPlayer (uuid);
setVotes (uuid, votes);
}
} catch (SQLException e) {
// TODO auto-generated catch block
e.printStackTrace ();
}

}

public static void addVotes (String uuid, Integer votes) {

try {
if (playerExist (uuid)) {
setVotes (uuid, Integer.valueOf (getVotes (uuid) .intValue ()) + votes.intValue ());
} else {
createPlayer (uuid);
addVotes (uuid, votes);
}
} catch (SQLException e) {
// TODO auto-generated catch block
e.printStackTrace ();
}
}

public static void removeVotes (String uuid, Integer votes) {

try {
if (playerExist (uuid)) {
setVotes (uuid, Integer.valueOf (getVotes (uuid) .intValue ()) - votes.intValue ());
} else {
createPlayer (uuid);
removeVotes (uuid, votes);
}
} catch (SQLException e) {
// TODO auto-generated catch block
e.printStackTrace ();
}
}
}

ga

When setting the parameter values, you use the indices 0 and 1 for one query. For another, only index 1. Shouldn't that be index 0?

Bu

The error lies in your first SQL query. You can read that in the stack trace:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '' Votestats 'WHERE' UUID '=' cf62fd90-e046-4b75-ad80-c6b633b3fc23 '' at line 1
(…)
at de.freundesgame.mysql.SQLStats.playerExist (SQLStats.java:14)

Specifically, it is the quotation marks that you use that trigger the error. Single quotation marks are not allowed here. However, apostrophes do:

SELECT 'UUID' FROM 'Votestats' WHERE 'UUID' =?

Read about it here:

The regular quote character is the backtick character - ', but if the ANSI_QUOTES
https://mariadb.com/kb/en/sql-mode/ option is specified, a regular double quote - "may be used as well. (…)

https://mariadb.com/kb/en/identifier-names/

You should of course also adapt your other queries to this effect.