Skip to content
Advertisement

MySQL Workbench doesn’t “see” updates from JDBC Java program

I have this code

    public PreparedStatement InsertDepartmentQuery() {
    try {
        ps = conn.prepareStatement("INSERT INTO department (DepartmentNo,DepartmentName,DepartmentLocation) VALUES (?,?,?)");
    }
    catch(SQLException e) {
        e.printStackTrace();
    }
    
    return ps;
}

and

public void InsertyTuple() {
    
    int a  = -1;
    ps = InsertDepartmentQuery();
       
    try {
    ps.setInt(1, DeptNo);
    ps.setString(2, DeptName);
    ps.setString(3, DeptLocation);
    a = ps.executeUpdate();
    }
    catch(SQLException e) {
        e.printStackTrace();
    }
    System.out.println(a);
}

and

      Department test = new Department(106, "TB_1", "Tabuk");
  
  test.InsertyTuple();

It executes fine in Eclipse, even a select query in there returns the expected results. But none of the inserts are showing up in MySQL Workbench. I tried restarting the connection and it didn’t work. Autocommits are on as when I tried to do a manual commit it told me so.

Advertisement

Answer

Wrong schema name

Well I found the problem so I’ll just leave the answer and feel stupid later.

I had the connection started as

conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=CONVERT_TO_NULL", username, password);

when it should’ve been

conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/project?zeroDateTimeBehavior=CONVERT_TO_NULL", username, password);

the “project” replacing “mysql” is the name of my schema in MySQL.

Advertisement