More Database Woes - the console spits out an error(see Code)

  • java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at pluginapi.PluginEventHandler.triggerEvent(SourceFile:166)
    at aF.b.a(SourceFile:171)
    at aF.b.messageReceived(SourceFile:121)
    at k.e.a(SourceFile:109)
    at k.c.run(SourceFile:65)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    at Commands.Commands.onCommand(Commands.java:79)
    ... 9 more
    Mirrawe helped me and I still cannont figure this out....

  • Please use the code tag for posting any source code, otherwise the indentings get lost, which makes the code difficult to read:


    When writing a plugin, it's also helpful to have a look at the output console, since it will print errors in case something goes wrong. On a server, just check the server output, on the client (when playing singleplayer), you can set "game_debug_console" in the config.properties file to true.


    In this case the INSERT statement throws an SQL exception, since no column "text" was found. The first CREATE statement does not create a column "text" (it neither creates a column "read")

  • Now the console says "Recpiant is a "Column," it is clearly in the VALUES I've tried everything to write a variable, coukd someone please tell me what the heck I am doing wrong?

  • If you want to enter a text, you always have to use single quotes ('), i.e. your INSERT statement should look like this: INSERT INTO MailPeople ('player_name', 'recipient_name', 'time', 'text', 'read') VALUES ('Recipiant', 'fromwhom', 'booger', 'Booty Call', 0);

  • Java
    "INSERT INTO MailPeople ('player_name','recipient_name','time','text','read') VALUES ("+Recipiant+","+fromwhom+",'booger','Booty Call' ,0);");


    You add Variables to an String in Java like this-> String var = "text"+variable;


    If your Variables are an String, then it have to look like:

    Java
    "INSERT INTO MailPeople ('player_name','recipient_name','time','text','read') VALUES ('"+Recipiant+"','"+fromwhom+"','booger','Booty Call' ,0);");
  • Hi,


    a better way ist to use Preparedstatements here is a simple example


    have a nice day and best regards


    Blacky1004

    Programmierer machen nie Fehler! Sie bauen nur neue Features ein....

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!