aspose file tools*
The moose likes Servlets and the fly likes Servlet and  writing to oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet and  writing to oracle" Watch "Servlet and  writing to oracle" New topic
Author

Servlet and writing to oracle

Milissa Jones
Greenhorn

Joined: Jan 12, 2003
Posts: 5
ok, I have a servlet that is performing a couple of things and then goes to write to the DB. The problem is that it compiles fine, but when ran it turminates when trying to create the ResultSet. Some code:
Create Connection:

Create Statement:

ResultSet Creation:

[ January 13, 2003: Message edited by: Cindy Glass ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Ouch! You have a System.exit in your servlet!?!
Get that out of there!
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Rather than a knee jerk reaction, I should probably explain.
Any code that calls System.exit is bad news when it is called in an application server.
If the server is not set up correctly, the System.exit call can cause the server to shut down! Even if the security rules are set up correctly so that the System.exit call is not allowed, the included code will not behave the way in which it was intended.
I'm guessing you have some configuration problems with your JDBC drivers that are causing the getDBConnection to fail (this is a very common problem), but the problem may be getting obscured by having the System.exit in there too.
It would be much better to throw an exception and manage the exception rather than deciding from the persistence layer that the application should exit...
Dave
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

It also looks like there is one important line missing at the beginning, the one that registers the driver with the DriverManager.
Class.forName("um, whatever the name of the Driver class is...");
Your driver documentation should have the name of the driver. I can go looking for it, but it depends on the driver you are using. This line of code gets the ClassLoader to load the Class, and while that is happening, the static initializer in the driver Class executes and registers itself with the DriverManager.
Dave
Milissa Jones
Greenhorn

Joined: Jan 12, 2003
Posts: 5
All the system.exit have been removed and now it runs up until the line below which is in the result set.
System.out.println("Creating DB Update...");
It is the line directly above the query which contains the insert statment. It just stops completely, no errors, no nothing.
SQL has been checked and can be inserted via hardcoading values.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Hi Melissa,
According to the database URL you show in your code, I assume you are working with an Oracle database. I also work with Oracle RDBMS (version 8.1.7.4 on SUN [sparc] with Solaris 7 and JDK 1.3.1), and I use the "executeUpdate()" method when I am trying to insert values into the database. Also -- as far as I know -- the (SQL) INSERT statement does not return anything (let alone a "ResultSet"), so what are you expecting to get back from your INSERT statement?
I don't know how you came up with the code you have shown, but have you looked at the example code available from Oracle's "Technet" web-site?
http://technet.oracle.com/sample_code/tech/java/sqlj_jdbc/content.html
Hope this helps you.
Good Luck,
Avi.
Milissa Jones
Greenhorn

Joined: Jan 12, 2003
Posts: 5
The servlet is currently being re-written, but I have another question.
When setting up the insert statement is it okay for all the sql to be on one line? Or is there a way to have it inserted on two lines. The reason why I ask this is because when I copy and paste the insert statement into the oracle db all on one line it tells me "Statement not properly terminated" but when I enter the statement on two lines the insert and field names on the first line and the values on the second it works fine.
Could the same thing be happening when entering the SQL from the servlet as one line?
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Melissa,
I don't know exactly what you mean, but I'm guessing that you are probably missing a space somewhere in your SQL text -- there should be a space between the closing bracket of the column list, and the "values" keyword.
Also, you don't need the "commit;" part of your (SQL) string -- your insert _should_ be committed immediately (since this is the default behaviour when using Oracle's JDBC driver -- you are using Oracle's JDBC driver?).
So if you drop the "commit;" part of your (SQL) string, then you should also drop the terminating ";" (semi-colon) from your INSERT statement -- since this is also not needed (when using Oracle's JDBC driver).
By the way, have you (or do you intend to) looked at the examples in the link I gave in my previous post? (Or are you just expecting us to hold your hand through the entire debug process?) The examples were very helpful for me.
Good Luck,
Avi.
Milissa Jones
Greenhorn

Joined: Jan 12, 2003
Posts: 5
I actually printed out the examples, started re-arranging my servlet, posted my additional question and then headed back down to my laptop to finsih the re-coding.
I've found that the examples contain a totally different structure than the one that we had been taught previously and is much easier for me at least to 'see' everything.
Milissa Jones
Greenhorn

Joined: Jan 12, 2003
Posts: 5
The server now has been completely re-coding following the structure of most of the examples and help that has been provided here however I now get a whole new error:
400 Bad Request
GET is not supported by this URL
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Milissa (I see I have been spelling your name wrong -- excuse me),
Sounds like your servlet does not define a "doGet()" method.
I don't know how much you know about servlets, so allow me to recommend the following web-site (if you don't already know about it):
http://www.servlets.com
Hope it helps.
Good Luck,
Avi.
 
jQuery in Action, 2nd edition
 
subject: Servlet and writing to oracle