Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A simple insert....

 
Raymond O'Leary
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
....wrecking my head!
Anybody got any clue as to why it isn't working? When I click the submit button the page displayed only contains the text used in the finally bit.
"DisConnecting From Server.... "
It doesn't even get this far:

Here's my full code:

<%@ page language="java" import="java.sql.*, oracle.jdbc.*" contentType= "text/html; charset=windows-1257" %>
<html>
<BODY>
<%
Connection con = null;
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
con = DriverManager.getConnection("jdbc racle:thin:@witnt07.wit.ie:1521 rawit","x", "x");
if ( ( request.getParameter("submit")).equals("submit") )
{
Statement statement1 = con.createStatement();
String sup=(String) session.getAttribute("username");
String grp = request.getParameter("t1");
String day = request.getParameter("D2");
String month = request.getParameter("D3");
String year = request.getParameter("D4");
String com = request.getParameter("comment");
String strSQL = "INSERT INTO SUPERLOG VALUES(NEXTSUPERLOG.nextval , "+" '"+sup+"' , "+" '"+grp+ "' , "+" '"+ day+"' , " + " '" +month +"' , "+" '"+year+"'," + "'" +com +"')";
String strSQL1 = "commit";
statement1.executeQuery(strSQL);
statement1.executeQuery(strSQL1);
con.close();
out.println("<font color=midnightblue><h3>You're log was added</h3></font>");
}
}
catch (SQLException sqle) {
out.println("SQL Bummer : " + sqle.getMessage());
}

catch (Exception e) {
out.println("Bit of a Bummer : " + e.getMessage());
}
finally {
try
{
if ( con != null )
{
out.println("<BR><BR>");
out.println("DisConnecting From Server.... ");
con.close();
}
}
catch (Exception e)
{
out.println("Bit of a Bummer Disconnecting : " + e.getMessage());
}
}
%>
</CENTER>
</BODY>
</HTML>
[/CODE]
Anybody have any ideas?
 
Lu Battist
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, I got an idea. Check the if statement, maybe its not true.
Try this:
if ( ( request.getParameter("submit")).equals("submit") ) {
out.println("Debug: inside if, add more debug statements around the query.");
...
} else {
out.println("Debug: inside else, guess I'd better re-check the request paramenters.");
}
 
Raymond O'Leary
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lu you're a genius,
now if you could only tell me why the text in my text area is not goning into the database then I may propose.
I just got rid of the if itself by the way. Is this a bad idea?
CHEERS!!
 
Raymond O'Leary
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All working thanks very much
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
minor remark:
"You're log was added" isn't propper english.
It means "You are log was added" which isn't of much sense.
"Your log was added" is what you mean.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic