• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

The Network Adapter could not establish the connection

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try read this post: https://coderanch.com/t/79839/Oracle-OAS/JDBC-Oracle-Host
/Rene
 
Something must be done about this. Let's start by reading this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic