Vishwanath Dalvi
Vishwanath Dalvi

Reputation: 36621

how to check if a query has affected a row or not in Java Netbeans Oracle

static void firequery(String q)
{
try {

query=q;
Class.forName ("oracle.jdbc.OracleDriver");/*driver*/
   //System.out.println("call");
  con = DriverManager.getConnection(dbUrl, "system", "demo");

stmt = con.createStatement();
rs = stmt.executeQuery(query);
System.out.println("FIRE!!!!!!!!");
} //end try

catch(ClassNotFoundException e) {
}
catch(SQLException e) {
e.printStackTrace();
}}

I'm passing my query in firequery(s) function using following code.

String s = "Delete from Ticket where tno='"+jnumber1.getText()+"'";
humarr_conn.firequery(s);
if(query has deleted any 1 row)
JOptionPane.showMessageDialog(null, "Deleted successfully");       
else
JOptionPane.showMessageDialog(null, "Delete operation failed"); 

I'm not getting what would be my if condition? I'm using Java as FrontEnd and Oracle as backend.

I want function like mysql_rows_affected of php like in java.

Hoping for quick and positive response.

Upvotes: 0

Views: 492

Answers (1)

AlexR
AlexR

Reputation: 115328

Use executeUpdate(String sql) instead. It returns number of record changed by the query.

See javadoc: http://docs.oracle.com/javase/1.4.2/docs/api/java/sql/Statement.html

Upvotes: 2

Related Questions