This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

my result holding null values  RSS feed

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

 
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.
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch Swetha
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!