Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - ghostofkc

Pages: [1]
JavaOp Support Archive / Plug-in using JDBC
« on: April 17, 2009, 02:06:57 pm »
I started off trying to make my own bot to do some semi specialized things… but I am retarded. Then I found your program.
So I am having issues with making JDBC work in the context of a plug-in for JavaOp2.

Admittedly I suck at java but, I have the connection working and performing queries outside of a plug-in. I looked on the forum and pervious posts about jdbc use in a plugin (there is one from 05) but they do not have any conclusions.

The error I get is “com.mysql.jdbc.Driver” which I understand (I think) to be a class path issue. But, I have included and referenced it just like I did in the standalone script (where it works).

So I guess the question is… what is different about using jdbc in the context of a plug-in / what am I fucking up.
Code: [Select]
        else if(command.equalsIgnoreCase("playgame"))
        //error catch
        if(args.length == 0)
                throw new CommandUsedImproperly("Error.", user, command);
        //end error catch
        Connection conn = null;

                String userName = "USERNAME";
                String password = "PASSWORD";
                //String url = "jdbc:mysql://localhost/ladder";
                String url = "jdbc:mysql://";
                Class.forName ("com.mysql.jdbc.Driver").newInstance ();
                conn = DriverManager.getConnection (url, userName, password);
                out.sendTextUserPriority(user, "Database connection established.", loudness, PRIORITY_LOW);
                //query perform
                Statement stmt = conn.createStatement();
                ResultSet rs;
                rs = stmt.executeQuery("SELECT id FROM users WHERE alias = 'Creed'"); //test line
                while ( ) {
                    String id = rs.getString("id");
                    out.sendTextUserPriority(user, id, loudness, PRIORITY_LOW);
                    //converting from sting to int for id so checks can be done
                    int idNum = Integer.valueOf(id).intValue();
                    if (idNum == 0)
                    out.sendTextUserPriority(user, "sorry! username does not exist.", loudness, PRIORITY_LOW);
                //end query preform
            catch (Exception e)
            * this is erroring because jdbc is not loading or something. /cry sad panda - 4/17/2009 ghost
            out.sendTextUserPriority(user, "Cannot connect to database server.", loudness, PRIORITY_LOW);
            out.sendTextUserPriority(user, e.getMessage(), loudness, PRIORITY_LOW);
                //System.err.println ("Cannot connect to database server");
            //this trys to close the conection after the query is done
                if (conn != null)
                        conn.close ();
                        //this is active for debuging will not talkie once it is working.
                        out.sendTextUserPriority(user, "Database connection terminated.", loudness, PRIORITY_LOW);
                    catch (Exception e) { /* ignore close errors */ }
            //end connection close

below links are to all of the code if anyone cares -  jdbc connection plugin for javaop2 - jdbc connection

I know this is probably a lame question but I cant find an answer to this on google or anything… probably because I don’t know what the problem is so I am looking up the wrong thing but what ever.

Thanks for the help.

Pages: [1]