File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Servlets And Database Connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Reply locked New topic
Author

Servlets And Database Connection

suraj sheikh
Greenhorn

Joined: Mar 07, 2008
Posts: 23
hello everyone,

this is the only place i can get help !

Here are the details

I have an html page, then i get the parameters to the servlets.
Then i have a standalone class responsible for data base connection.

Here is the directory structure
c:\my projects\boaintegratedworkflow\src\com\system33\model\MyOracleConnection.java

The source code is :

package com.system33.model;
import java.sql.*;
public class MyOracleConnection {
public String result="uninitialized" ;
public Connection conn=null;
public Connection connectionDriver() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc racle:thin:@localhost:1521:XE", "system","administrator");
} catch (Exception e) {
e.printStackTrace();
result="error in connection";
}
return conn;
}
public String fetchData() {
try {
Statement stmt = this.connectionDriver().createStatement();
String query="select * from boaiw";
ResultSet rs = stmt.executeQuery(query);
while(rs.next()) {
System.out.println(rs.getString(1));
result=rs.getString(1);
}
} catch (Exception e) {
e.printStackTrace();
//result="error in data return" ;
}
return result;
}
public static void main(String[] args) {
com.system33.model.MyOracleConnection obj=new com.system33.model.MyOracleConnection();
System.out.println(obj.fetchData());
}
}

This is the servlet Code

c:\my projects\boaintegratedworkflow\src\com\system33\model\Submit.java

package com.system33.web;
import com.system33.model.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class Submit extends HttpServlet {
public Connection conn;
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,

ServletException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("Selection Advice<br>");
out.println("<br> Value of connection ");
com.system33.model.MyOracleConnection obj = new com.system33.model.MyOracleConnection();
out.println("<br> Data Fetched "+obj.fetchData());
out.println("<br> Data Fetched "+obj.connectionDriver());
out.println("<br> This is the new servlet<br>");
}

}

The class file lands in
c:\my projects\boaintegratedworkflow\classes\com\system33\model\MyOracleConnection.class
c:\my projects\boaintegratedworkflow\classes\com\system33\web\Submit.class

And this is not fetching the data, it throws an exception whic i am not able to see as its not being displayed on the page

Please Help me guys ! i need it
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60761
    
  65

Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Your first step should be to find the stack trace of the exception. Normally you will find that somewhere in the logs of your application server. It will be very difficult to solve the problem without that information.
suraj sheikh
Greenhorn

Joined: Mar 07, 2008
Posts: 23
Thanks for your reply, But can you help me how to get the log on tomcat
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60761
    
  65

Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Servlets And Database Connection
 
Similar Threads
JAVA AND DATABASE CONNECTION
JAVA PACKAGE RUNTIME ERROR
Java Package RUNTIME error
JAVA DATABSE
Java Runtime Error