jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes A simple  insert.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "A simple  insert...." Watch "A simple  insert...." New topic

A simple insert....

Raymond O'Leary

Joined: Mar 23, 2004
Posts: 24
....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" %>
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";
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 {
if ( con != null )
out.println("DisConnecting From Server.... ");
catch (Exception e)
out.println("Bit of a Bummer Disconnecting : " + e.getMessage());
Anybody have any ideas?
Lu Battist
Ranch Hand

Joined: Feb 17, 2003
Posts: 104
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

Joined: Mar 23, 2004
Posts: 24
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?
Raymond O'Leary

Joined: Mar 23, 2004
Posts: 24
All working thanks very much
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

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.

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: A simple insert....
It's not a secret anymore!