File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes my result holding null values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "my result holding null values" Watch "my result holding null values" New topic
Author

my result holding null values

Swetha Bhagavathula
Ranch Hand

Joined: Jan 04, 2011
Posts: 112


/*
* 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

SCJP5
Eshwin Sukhdeve
Ranch Hand

Joined: Mar 15, 2012
Posts: 79
is that query deleting record from table.
Swetha Bhagavathula
Ranch Hand

Joined: Jan 04, 2011
Posts: 112

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

Joined: Jan 22, 2007
Posts: 196
// 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

Joined: Jan 04, 2011
Posts: 112

]
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

Joined: Oct 21, 2008
Posts: 1106

Welcome to the ranch Swetha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: my result holding null values
 
Similar Threads
refresh table doesn't work
Struts config error , controller not redirecting to required screen.
Making ResultSet unEditable
Making ResultSet unEditable
An unexpected error of Java Runtime Environment: