General Discussion (#1) - SQl help for bot (#14) - Message List

SQl help for bot

this is my code for sql. Problem is bot doesn't write to the sql database. I'm sure its a dumb error because I haven't programmed something in a few years. That query isnt done yet. I still need to add to make it update if theres a duplicate key. Any ideas?

public void handleEvent(PlayerEntered event)

{

String name = event.getPlayerName(); String squad = event.getSquadName(); short wins = event.getWins(); short losses = event.getLosses(); int kpoints = event.getKillPoints(); int fpoints = event.getFlagPoints();

String query = "INSERT INTO stat (name, squad, wins, losses, kpoints, fpoints) VALUES('"+name+"','"+squad+"','"+wins+"','"+losses+"','"+kpoints+"','"+fpoints+"') ; try {

m_botAction.SQLQuery(mySQLHost, query);

} catch (SQLException e) { e.printStackTrace();

}

}

  • Message #18

    Do you get a stacktrace when you try?
    If not, are you sure the event is even fired? (Have you requested the event from the EventRequester?)

    • Message #19

      I don't get a stacktrace and I have the event requested from the EventRequester.

      • Message #20

        You're missing an end quotation at the end of your String query.

        String query = "INSERT INTO stat (name, squad, wins, losses, kpoints, fpoints) VALUES('"+name+"','"+squad+"','"+wins+"','"+losses+"','"+kpoints+"','"+fpoints+"') ";

        I suppose I'll ask the obvious questions… do you have your sql.cfg setup properly with Connection Count being 1+ and your database's information filled in? Does your database contain a table named stat with the appropriate values etc.?

        • Message #21

          Quotation was there in my src. Heres a copy of my sql.cfg with pass blanked out and I have a table named stat with the appropriate values.

          [General] RetryCount=3 ConnectionCount=1

          [Connection 1] Name1=db229467413 Driver1=com.mysql.jdbc.Driver Login1=dbo229467413 Password1=——- DataBase1=db229467413 Server1=db1302.perfora.net Port1=3306 MinPoolSize1=0 MaxPoolSize1=10 WaitIfBusy1=1

          • Message #22

            At the top of your java src do you have mySQLHost = "db229467413";?

            If that's correct try using an appropriate IP address of your host instead of the server name in your sql.cfg. I can't seem to ping db1302.perfora.net.

            • Message #23

              I have that except as a String. I tried using my second host and it still did not work there too.

      • Message #24

        When running the bot you must get some sort of error why this isn't working. Check the console window or the exception.log .

        • Message #25

          No error in console window or exception.log.

          • Message #26

            Heh….

            use m_botAction.SQLQueryAndClose(mySQLHost, query);

            • Message #27

              The method SQLQueryAndClose(String, String) is undefined for the type BotAction

            • Message #28

              He's using an older version TWCore, milosh.
              Probably revision 1320 from the Download page.

              • Message #29

                Work around it…

                use the following…

                m_botAction.SQLClose(m_botAction.SQLQuery(mySQLHost, query));

                • Message #30

                  The method SQLClose(ResultSet) is also undefined for the type BotAction. Any way I can get a more updated version?

                  • Message #31

                    See the wiki:Download page

                    • Message #36

                      Ok, I got back home and tried it. Bot doesn't respond to !help with new revison. Hub bot does though..