Solved Cannot use executeQuery() with MySQL

Discussion in 'Plugin Development' started by JjPwN1, Jan 4, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    JjPwN1

    I am coding MySQL into my plugin so that, when necessary, I can open up multiple Bukkit servers using that plugin, all reading and saving from the same database. I am 99.9% positive my url, username, and password for the MySQL database are correct - as when I made a mistake by trying to read from a non-existing column, it returned an error saying that column didn't exist. When I tried the right column, this error popped up:
    Code:
    00:40:22 [SEVERE] java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
    00:40:22 [SEVERE]    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    00:40:22 [SEVERE]    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
    00:40:22 [SEVERE]    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
    00:40:22 [SEVERE]    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
    00:40:22 [SEVERE]    at com.mysql.jdbc.StatementImpl.checkForDml(StatementImpl.java:434)
    00:40:22 [SEVERE]    at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1388)
    00:40:22 [SEVERE]    at com.pwncraftpvp.BbyCTF.MySQL.connectToDatabase(MySQL.java:23)
    00:40:22 [SEVERE]    at com.pwncraftpvp.BbyCTF.BbyCTFMain.onEnable(BbyCTFMain.java:501)
    00:40:22 [SEVERE]    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
    00:40:22 [SEVERE]    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
    00:40:22 [SEVERE]    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
    00:40:22 [SEVERE]    at org.bukkit.craftbukkit.v1_4_6.CraftServer.loadPlugin(CraftServer.java:282)
    00:40:22 [SEVERE]    at org.bukkit.craftbukkit.v1_4_6.CraftServer.enablePlugins(CraftServer.java:264)
    00:40:22 [SEVERE]    at net.minecraft.server.v1_4_6.MinecraftServer.j(MinecraftServer.java:321)
    00:40:22 [SEVERE]    at net.minecraft.server.v1_4_6.MinecraftServer.e(MinecraftServer.java:300)
    00:40:22 [SEVERE]    at net.minecraft.server.v1_4_6.MinecraftServer.a(MinecraftServer.java:259)
    00:40:22 [SEVERE]    at net.minecraft.server.v1_4_6.DedicatedServer.init(DedicatedServer.java:149)
    00:40:22 [SEVERE]    at net.minecraft.server.v1_4_6.MinecraftServer.run(MinecraftServer.java:399)
    00:40:22 [SEVERE]    at net.minecraft.server.v1_4_6.ThreadServerApplication.run(SourceFile:849)
    And for my connectToDatabase method:
    Code:
        public void connectToDatabase() throws SQLException{
            try{
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://pwncraftpvp.com/pwncraft_mctdm","pwncraft_jjpwn","PASSWORD");
                Statement statement = con.createStatement();
                String query = "INSERT INTO players VALUES ('SomeUserName', 'Corporal', 1, 1, 1, 1, 1, 1, 1)";
                ResultSet rs = statement.executeQuery(query);
                if(rs != null){
                    System.out.println("Found data.");
                }
            }catch(ClassNotFoundException e){
                e.printStackTrace();
            }
        }
    Not entirely sure what's wrong... I just see there's an error with .executeQuery(). Any help is very much appreciated.
     
  2. Offline

    nisovin

    You can't run an insert statement with executeQuery. Use execute or executeUpdate instead. The executeQuery method is for select statements.
     
    JjPwN1 likes this.
  3. Offline

    JjPwN1

    I was actually experimenting and I changed the query to SELECT and it worked. Yet, without your comment, it'd of taken me much more time to find that out. Thanks!
     
Thread Status:
Not open for further replies.

Share This Page