Java program will read from database, but not write to it

Posted by ck1221 on Stack Overflow See other posts from Stack Overflow or by ck1221
Published on 2012-12-05T16:58:12Z Indexed on 2012/12/05 17:03 UTC
Read the original article Hit count: 176

Filed under:
|
|

I have a Java program that successfully connects to a mysql database that is hosted on godaddy's server. I can read from that db with out issue, however, when I try to write to it with INSERT or UPDATE for example, the query does not execute. I am using the 'admin' account that I set up through godaddy, I realize this is not the root account. I have checked and verified that the connection is not read only, and have logged out of phpmyadmin while the query ran. I'm not sure what else I can try or if anyone has experienced this issue.

Maybe a setting to the connection I have failed to set? Or maybe its not possible since the db is hosted on godaddy's servers?

Any help is great!

Thanks.

Here is some relevant code:
Connection to db:

Connection con;
public DBconnection(String url, String user, String pass)
{
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            con = DriverManager.getConnection (url,user,pass);


            if(!con.isClosed())
                System.out.println("connecton open");
        } 
        catch (InstantiationException e) {e.printStackTrace();} 
        catch (IllegalAccessException e) {e.printStackTrace();} 
        catch (ClassNotFoundException e) {e.printStackTrace();} 
        catch (SQLException e) {e.printStackTrace();}
}

Send Query:

public ResultSet executeQuery(String query)
{
    ResultSet rs = null;

    try {
        Statement stmt = (Statement) con.createStatement();
        rs = stmt.executeQuery(query);

        //while(rs.next())
            //System.out.println(rs.getString("ticket_num"));
    } 
    catch (SQLException e) {}   

    return rs;
}

Insert Query (works in phpmyadmin):

conn.executeQuery("INSERT INTO tickets VALUES(55555,'12/01/2012','me','reports','test','','','0','Nope')");

© Stack Overflow or respective owner

Related posts about java

Related posts about mysql