aspose file tools*
The moose likes JDBC and the fly likes  The Network Adapter could not establish the connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark " The Network Adapter could not establish the connection" Watch " The Network Adapter could not establish the connection" New topic
Author

The Network Adapter could not establish the connection

andrea baratella
Greenhorn

Joined: Jul 01, 2002
Posts: 3
Hi all,
I'm new to Java and ODBC world, I'm tring to
connect to an Oracle database with a small java
servlet, but I find this error when I execute
the page. I'using Forte and iPlanet Web Server,
I have the same error using Tomcat server embedded
in Forte.
On the contrary, if I put my code in a simple
stand alone java program it works fine.
Is it an user identification problem of the
web server?
Can you help me, please.
Here is the code of my servlet:
/*
* Pippo.java
*
* Created on June 20, 2002, 4:00 PM
*/
import java.io.*;
import java.util.*;
import java.sql.*;
import oracle.jdbc.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*
* @author baratella
* @version
*/
public class Pippo extends HttpServlet {
/** Global Variables
*/
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
Connection con = null;

/** Initializes the servlet.
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
/** Load driver
*/
String driver = "oracle.jdbc.driver.OracleDriver";
Class.forName(driver);
/** Get Connection to Database
*/
String url = "jdbc racle:thin:@<host>:<port>:<sid>";
String user = "andrea";
String pwd = "baratella";
con = DriverManager.getConnection (url, user, pwd);
} catch (ClassNotFoundException cnfex) { //necessario per Class.forName()
/* process ClassNotFoundExceptions here */
cnfex.printStackTrace();
} catch (SQLException sqlex) {
/* process SQLExceptions here */
sqlex.printStackTrace();
}
}
/** Destroys the servlet.
*/
public void destroy() {
super.destroy();
try{
if ( con != null )
con.close();
} catch( java.sql.SQLException e ){}
}
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
//response.setContentType("text/html");
//java.io.PrintWriter out = response.getWriter();
/* output your page here
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet</title>");
out.println("</head>");
out.println("<body>");
out.println("</body>");
out.println("</html>");
*/
//out.close();
}
/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);

response.setContentType("text/html");
/**Output variable
*/
PrintWriter out = response.getWriter();

/**SQL variable
*/
Statement stmt = null;
ResultSet result = null;
out.println("<html>");
out.println("<head>");
out.println("<title>Connessione</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Connessione ad un Database Oracle</h1>");

try {
/** Submit query
*/
stmt = con.createStatement();
result = stmt.executeQuery ("SELECT PART_NUMBER, DESCRIZIONE FROM ELENCO_PARTI;");
/** Create output
*/
while(result.next()) {
/** Generate output from ResultSet
*/
out.println( result.getString(1) + " " + result.getString(2) );
}
/** close query result
*/
if (result != null) {
result.close();
}
/** close query
*/
if (stmt != null) {
stmt.close();
}
} catch (SQLException sqlex) {
sqlex.printStackTrace(out);
}
out.println( "</body>" );
out.println( "</html>" );
out.flush();
out.close();
}
/** Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);
}
/** Returns a short description of the servlet.
*/
public String getServletInfo() {
return "HelloWorld Servlet SDK Sample - Netscape Enterprise Server 4.0";
}
}

Here the code of my small program:
import java.sql.*;
class jdbc
{
public static void main (String args[]) throws SQLException
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection ("jdbc racle:thin:@<host>:<port>:<sid>", "andrea", "baratella");
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery ("select PART_NUMBER, DESCRIZIONE from ELENCO_PARTI");
int i = 1;
while (rset.next())
{
System.out.println (i + " " + rset.getString (1) + " " + rset.getString (2));
i = i + 1;
}
rset.close();
stmt.close();
conn.close();
}
}
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Try read this post: http://www.coderanch.com/t/79839/Oracle-OAS/JDBC-Oracle-Host
/Rene


Regards, Rene Larsen
Dropbox Invite
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The Network Adapter could not establish the connection
 
Similar Threads
Using get() and post() together
Checking user selection
EJB, JNDI
org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException: 8
Hello world ejb3 problem