Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Java statement to read a SQL table

Okay right now I'm trying to make it so if a user inputs a command, it'll check a database and do the actions according to the databases numbers

Here's the java sided part (atleast my attempt of what i got so far)
Code
    if (command.startsWith("auth") && command.length() > 5) {
        String theAuth = command.substring(5);
        try {
            Statement statement = con.createStatement();
            String query = "SELECT * FROM votes WHERE authcode = '" + theAuth + "'";
            ResultSet results = statement.executeQuery(query);
            if(results.next()) {
                ps.close();
                ps = Database.getConnection().prepareStatement("UPDATE votes SET used = '1' WHERE authcode = ?");
                ps.setString(1, playerCommand.substring(5));
                ps.executeUpdate();
                //givem the reward
                sM("Thanks for voting for us! Enjoy your reward. Remember to vote daily!");
            } else {
                sM("Error! It appears this isn't a valid auth code. Please double check it. ("+theAuth+")");
            }
        } catch (Exception e) {
            sM("Invalid format, please claim using this format. ::auth @red@authcode");
        }
        return;
    }

Basically, what i'm trying to do is so when they type cmd:auth 95910, it will..
1) check to make sure that the auth 95910 is there
2) if it is, check if it's been used already
3) if not, check what reward they should get
4) set a string as the reward

here's a picture of the database
[img]http://i56.[censored].com/2n0izk2.jpg[/img]

explanation of all of the things
id, time, ipaddress, username, guid; not important for the current time being
authcode; the custom code only for that specific person
used; checks to see if they've claimed their reward yet
reward; an acronym of the reward they're attempting to get

summary: need someone to rewrite my command with decent stability to check the database if the auth they're trying to claim exists, then if it does exist, check if they've already claimed it or not, and if they havn't claimed, have it check what the reward is (set this to a string after checking it)
please and thank you, willing to pay $10 via paypal
msn; [email protected]
, still need this, paying $10
Hi,
I am willing to help. I can't PM. Can I have your email id?

Thanks
(Dec 13, 2016 12:56 AM)harshita251194 Wrote:  Hi,
I am willing to help. I can't PM. Can I have your email id?

Thanks

This thread is over 5 years old. Stop gravedigging.
woah hahaha #RIPSEARCHBUTTON
[Image: 0554f17a8b77a40202165c50d6e1ec51.gif]


Possibly Related Threads...
Thread / Author Replies Views Last Post
by lilsergsApr 26, 2023 10:15 AM 0 116 Apr 26, 2023 10:15 AM
Last Post: lilsergs
[Java] by OBAMASELFApr 23, 2019 12:42 AM 4 244 Apr 23, 2019 12:42 AM
Last Post: Joseph Stalin
[Java] by Ashish BishtNov 14, 2016 04:27 AM 2 181 Nov 14, 2016 04:27 AM
Last Post: GammaG