• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

my result holding null values

 
Swetha Bhagavathula
Ranch Hand
Posts: 112
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package PSDemos;
import java.sql.DriverManager;
import java.util.Scanner;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.ResultSet;



public class DeleteTest1 {

public static void main(String[] args) {
Connection con=null;
PreparedStatement ps=null;


try {

// read input values from keyboard


// create jdbc con obj
// Class.forName("oracle:jdbc:driver:OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");

// create query with parameters
String qry="delete from students where stno=?";
ps.setInt(1,001);



// prepare sql query with variables(delete from students where stno=001)


// create jdbc preparedStatement obj representing pre-compiled qry
ps=con.prepareStatement(qry);
// execute the qry each time
int result=ps.executeUpdate();
// process the result




}
catch (SQLException sqe) {
sqe.printStackTrace();
}
catch (Exception ex) {
ex.printStackTrace();

}
finally {
// close jdbc objs
try {
if (ps!=null) {
ps.close();
}
}
catch (Exception ex) {ex.printStackTrace();


try {

if (con!=null) {
con.close();

}
} catch (Exception e) {
ex.printStackTrace();
}
}
}//finally


}//main
}//class
 
Eshwin Sukhdeve
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is that query deleting record from table.
 
Swetha Bhagavathula
Ranch Hand
Posts: 112
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eshwin Sukhdeve wrote:is that query deleting record from table.

sorry !i rectified my mistake..Here my code goes...
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// execute the query
int result=ps.executeUpdate();
// process the qry
if (result==0) {
System.out.println(stno+" "+"record could not delete.");
} else {
System.out.println(stno+" "+"record deleted successfully.");
}


your result would either be 0 or more than 0. Where would it be null?
 
Swetha Bhagavathula
Ranch Hand
Posts: 112
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
]
Yes.Previously I posted my error code then could rectify later and posted the executed code(without errors).Sorry for the in-convenience.
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch Swetha
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic