• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Iam unable to execute insert and select statements using batches

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Raghavendra ReddyI
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raghavendra ReddyI wrote:

Raghavendra ReddyI wrote:

Raghavendra ReddyI wrote:import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class DeleteFlightData extends HttpServlet
{
Connection con=null;
Statement stmt=null;
int fid1,pid1;
String pname1;

public void init(ServletConfig config)throws ServletException
{
super.init(config);
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","system");
}
catch(Exception e)
{
}
}

public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
fid1=Integer.parseInt(req.getParameter("fid"));
try
{
stmt=con.createStatement();
con.setAutoCommit(false);
String query="select pid,pname form pilot where fid="+fid1;
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
pid1=rs.getInt("pid");
pname1=rs.getString("pname");
}
String query1="delete from flight where fid="+fid1;
stmt.addBatch(query1);
String query2="insert into pilot (pid,pname,fid,onduty,free,leave) values ("+pid1+",'"+pname1+"',0,'-','free','-')";
stmt.addBatch(query2);
int[] count = stmt.executeBatch();
con.commit();
}
catch(SQLException sqle)
{
out.println("<div align='center' style='color:#FF0000;font-size:25px;'>");
out.println("

Cannot be deleted........!!!

");
out.println("</div>");
}
catch(Exception e)
{

out.println("<div align='center' style='color:#FF0000;font-size:25px;'>");
out.println("

Cannot be added........

");
out.println("</div>");
}
}//End of doPost

}//end of class

 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem, I think, is that when an exception is thrown, your code throws away all the information in the exception and just displays something generic in the response. You should at least log the exception before doing that.

The reason I think this is the problem is that when you have "select ... form ..." instead of "select ... from ...", as your posted code does, then an exception will be thrown telling you that your SQL is not well-formed. But since you ignore the exception, you have no way of telling that.
 
Raghavendra ReddyI
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but still iam unable to execute
exception thrown is
java.sql.BatchUpdateException: error occurred during batching: ORA-02291: integrity constraint (SYSTEM.FK_PILOT) violated - parent key not found
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's good -- at least you have an error message. Now you need the full stack trace, not just the error message. It will tell you what line of code threw the exception, and that's where you should start looking. So you should write out the full stack trace when an exception is thrown, and you can do that by calling the exception's "printStackTrace()" method.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your first sql query select has an issue. Revise your sql is needed to get your code getting executed correctly.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic