I am using Microsoft Azure's cloud database for the first time and all SQL (SELECT, UPDATE and DELETE)
are working except for insert. When I try to insert into a table it gives me this exception: com.microsoft.sqlserver.jdbc.SQLServerException
: A result set was generated for the update.
Keep in mind all the SQL works when done in the database itself.
I noticed it only gives it to me when using stat.executeUpdate()
when I change it to stat.executeQuery()
there are no exceptions and is "successful" but it does not insert anything into the table.
I have updated all software and still, nothing has changed.
I found out that one INSERT works but not the other.
Edit: The other question is returning a comment while my method is a void and is not using stat.executUpdate() to get the comment.
public static void main(String[] args)
{
ConnectDB();
insertHistory("5364", 10, "5005", "353", "6", 10, "admin");
}
This is the broken INSERT:
public static void insertHistory(String sInt, int iBase, String P1, String P2, String P3, int pBase, String Email)
{
try
{
stat = con.prepareStatement("INSERT INTO dbo.tblHistory (Num, BaseForNum, P1, P2, P3, BaseForP, UserID) VALUES (?, ?, ?, ?, ?, ?, ?)");
stat.setString(1, sInt);
stat.setInt(2, iBase);
stat.setString(3, P1);
stat.setString(4, P2);
stat.setString(5, P3);
stat.setInt(6, pBase);
stat.setInt(7, getUserID(Email));
stat.executeUpdate();
}
catch(SQLException e)
{
System.out.println(e);
JOptionPane.showMessageDialog(null, "Could not save to tblHistory.");
}
}
This is the working INSERT:
public static void insertAccount(String Email, String Password)
{
try
{
stat = con.prepareStatement("INSERT INTO dbo.tblUser (Email, Password) VALUES (?, ?)");
stat.setString(1, Email);
stat.setString(2, Password);
stat.executeUpdate();
JOptionPane.showMessageDialog(null, "Account created.");
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null, e);
}
}
I expect it to have no exception and insert into the database but I get an SQL exception.