Problems connecting to an oracle db whit servlets

hi there!
I am trying to connect to my Oracle database. When I write my program as a JSP It connects but when I use the same within a servlet.
It does not work!!!
I use
- Tomcat 4.1.24
- J2SDK 1.4.2
By the way, I have already put the Oracle JDBC JARs (classes12.jar & classes111.jar) in the
TOMCAT_HOME/common/lib directory so my JSP's can find them and they run very well.
And I have defined the CLASSPATH environment variable
Also I have included the JARs files in my lib directory.
TOMCAT_HOME\webapps\myweb\web-inf\lib
But when i try to compile my servlets can't find the JARs files.
This is the error that I got while compiling.
servletdb.java:22: unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrownClass.forName("oracle.jdbc.driver.OracleDriver").newInstance();
^
servletdb.java:22: unreported exception java.lang.InstantiationException; must be caught or declared to be thrownClass.forName("oracle.jdbc.driver.OracleDriver").newInstance();
^
2 errors
---------------> this is my code <-------------------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
public class servletdb extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String queryString;
queryString = "select * from TABLE";
try
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection dbconn=DriverManager.getConnection("jdbc:oracle:thin:@url:port:dbname","user","pw");
out.println("You are connected (Too)!<br>");
out.println("Congratulations!!<br><br>");
Statement stmt=dbconn.createStatement();
ResultSet rs=stmt.executeQuery(queryString);
while(rs.next())
out.println(" <tr><td>" + rs.getString(1));
out.println("</td><td>" + rs.getString(2));
out.println("</td><td>" + rs.getString(3));
out.println("</td><td>" + rs.getString(4));
out.println("</td><td>" + rs.getString(5) + "</td></tr>");
rs.close(); // need to close all of these
stmt.close(); //
dbconn.close(); //
thanks in advance

Now, I got this message. What am i doing wrong??
servletdb.java:16: unreported exception java.lang.IllegalAccessException; must be caught or declared to be thrown Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
^
servletdb.java:32: unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
^
servletdb.java:32: unreported exception java.lang.InstantiationException; must be caught or declared to be thrownClass.forName("oracle.jdbc.driver.OracleDriver").newInstance();
^
3 errors
Any further help would be much appreciated.

Similar Messages

  • Problem connect form6i and Oracle Database 10g

    I can't connect form6i to Oracle Database 10g
    When complete user/password@database fatal error produce:
    "Oracle Forms Designer has encountered a problem and needs to close. We are sorry for the inconvenience"
    Error Detail:
    AppName: ifbld60.exe     AppVer: 6.0.8.27     ModName: ora805.dll
    ModVer: 0.0.0.0     Offset: 000b4f04
    Product Install:
    - Forms Version: Forms [32 bits] Versión 6.0.8.27.0
    - Oracle Database: 10.2.0
    - Win XP professional with SP2.
    Any idea what might cause Forms to shutdown ubnormally?
    Thanks

    If your database is using the AL32UTF8 character set, Forms 6i cannot connect.
    Read this thread:
    connecting form 6i  to oracle database 10G express edition

  • Problem connecting Mapview to Oracle Database(Add a data source)

    I’m a neophyte to the mapviewer and I’ve run into a very primitive problem. I can’t view the sample maps in the mapviewer. I can’t connect to the database where I've loaded the sample oracle data (mvdemo.zip) to the database. I have the mapviewer running. I’ve checked my tnsnames to confirm the connection used by other oracle application (sql) and confirmed that the spatial files exists on the database.
    Below is my platform inform
    Platform
    For MapView
    We have Java- j2se_1.4.2_09
    My local system is Microsoft Windows 2000.
    Connect to Oracle 9.2.0.4.0 and 10.1.0.3.1 on separate machines
    Here is my connection infor:
    <?xml version="1.0" standalone="yes"?>
    <non_map_request>
    <add_data_source
    name="mvdemo"
    jdbc_host="medea"
    jdbc_port="1521"
    jdbc_sid="orcl"
    jdbc_user="gda_stock"
    jdbc_password="!********"
    jdbc_mode="thin"
    number_of_mappers="3" />
    </non_map_request>
    Here is the error I received:
    <?xml version="1.0" encoding="UTF-8" ?>
    <oms_error>Message:[MapperConfig] cannot add map data source. Fri Aug 26 17:28:04 CDT 2005 Severity: 0 Description: at oracle.lbs.mapserver.core.MapperConfig.addMapDataSource(MapperConfig.java:583) at oracle.lbs.mapserver.MapServerImpl.addMapDataSource(MapServerImpl.java:315) at oracle.lbs.mapserver.oms.addDataSource(oms.java:1241) at oracle.lbs.mapserver.oms.doPost(oms.java:409) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:810) at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:322) at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112) at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186) at java.lang.Thread.run(Unknown Source)</oms_error>

    Hi, is there anyone here who can help me.....thanks in advance!

  • Problem connecting java to oracle

    new to jdbc so might appear stupid, but i have tried to create a basic connection from a java application to oracle using the following code
    Class.forName("oracle.jdbc.driver.OracleDriver") ;}
    system.out.println("msg1");
    con = DriverManager.getConnection
    ("jdbc:oracle:thin:@//(local host)","(username)", "(password)");
    system.out.println("msg2");
    but when i run the application it displays msg1 fine, but then seems to run into a problem because it is contiuously running without carrying out the other commands, and needs to be stopped manually. problem is i done the exact same thing on another computer and works fine. Was wondering if a firewall problem or something, any help would be appreciated.

    It looks like the connection URL is not complete. Need to specify the database port number and SID (1521, and XE, for example).
    The examples in Oracle's JDBC FAQ page:
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@//myhost:1521/orcl", "scott", "tiger");
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:thin:scott/tiger@myhost:1521:orcl);
    Link:
    http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#03_01

  • Problem Connect forms6i to Oracle Database 10g

    Hi, I have a trouble connecting Forms6i ( Patch 15) to oracle Database 10g, the forms crash when trying to connect to database some hints for this trouble.
    Best Regards
    Abarra

    Joel,
    My problem is that forms6i crash and Don't give me any information, i think the problem i SQLNET 8.0.6, because i have trouble with sqlplus, query builder,etc. all products of the forms6i CD.
    Is posible to user forms6i with another version of SQLNET ?

  • Problem connection Developer to Oracle Server

    I've installed Oracle Personal Edition and Forms Developer6i.
    My oracle database loads up with no problems and I can do sql work to my hearts content. I can create tables and store data in there and retrieve it with select statements but as soon as I go into developer I get one of two things:
    1) I type in my username/password and specify the database name I get this error:
    ORA-12154:TNS:could not resolve service name
    2) Or I type in my username/password and leave the database field blank (which I do in sql plus to connect) and I get this error:
    ORA-01034:ORACLE not available.
    But with either of these I have the database running and can as I previously said do SQL work. Any help would be greatly appreciated thanks.

    For Personal Oracle 8i and Developer 6i to work u have to do the following:
    1. U should have Installed the Net8 Products when Installing the Developer 6i.
    2. Configure the Listener on the Server ( Listener.ora)
    3. Ensure that the Listener is up and running
    4. Configure Net8Easy Configuration ( TNSNAMES.ORA will be appended by this tool)
    5. Test the Connection
    Though it is all installed in One PC. U have to do this.
    Thiru

  • Problem connecting using VB Oracle Data Control oradc.ocx but otherwise ok.

    I am trying to run one of the sample vb apps DataCtrl that uses the Oracle Data Control (oradc.ocx) to simplify connecting to a database and getting the data into a databound control. I have tried every combination of name/id/pw and get the same error - ORA-12154:TNS:could not resolve service name.
    I have 2 of the sample databases created - "employees" and "demo". Using XE, i can open and view both db's with no problem. Using the ODBC configuration dialog I can configure and test the connection to both and tests ok. I have used programs to convert Oracle to Excel and Excel to Oracle and both find the db with no problem either.
    If I tnsping to XE, employees or demo, the response is negative. The file tnsnames.ora exists in the /admin dir and lists only XE. The file sqlnet.ora has nothing (except comments) in it.
    I have read every bit of documentation on the internet and no help. I just opened "employees" and "demo" again with XE without a problem. However when I try to run the Oracle/Excel conversion programs now, they are now showing the 'name error also. I have tried both the sample VB app and the Oracle/Excel converter programs with XE/employees open and closed and it makes no difference.
    Everything that I have read indicates that you should be able to use the actual db name, ie; "employees". I have run out of combinations of names/ids/pws and hope I can get some help here. Thanks in advance.

    The firewall was blocking TNSLSNR.exe!

  • Problem Connecting to my Oracle 10g

    I have been using Oracle 10g for about an year on my PC and just a couple of days back theres been this problem that wont let me connect to any of my local DBs.. neither can i start sqlplus in prompt, i am using Windows XP, when i try to connect to any local DB it says "Service Unavailable", and the connection times out if a rmote connection is attempted, i know i must have messed up some service or folder during some other software installation or un-installation or something like that, while trying to use the command sqlplus in prompt it gives the following error:-
    Error 6 initializing SQLPlus*
    Message file sp1<lang>.msb not found
    SP2-0750 : You may need to set ORACLE_HOME to your oracle software directory
    The thing is i have checked all my environment variables and they are all there and correct...
    There are other forum threads on the same topics but none gives a solution.. the only solution i got is re-installation of Oracle and registry cleaning.. and i wouldnt wanna do that..
    I have also tried connecting after starting the stopped services including OracleXEClrAgent, OracleTNSListener and ORACLEMTSRRecoveryService but still wouldnt work.. and evertime i try to start the service OracleXETNSListener using the net start command, it gives the message the OracleXETNSListener service could not be started, The service did report an error..
    Can anyone help??
    Edited by: user9038492 on Nov 26, 2010 9:19 PM
    Edited by: user9038492 on Nov 26, 2010 9:20 PM
    Edited by: user9038492 on Nov 26, 2010 9:22 PM
    Edited by: user9038492 on Nov 26, 2010 9:24 PM

    Response to LSNRCTL is :-
    LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 27-NOV-2010 10:33:23
    Copyright (c) 1991, 2005, Oracle. All rights reserved.
    Message 1053 not found; No message file for product=NETWORK, facility=TNSTNS-125
    57: Message 12557 not found; No message file for product=NETWORK, facility=TNS
    TNS-12560: Message 12560 not found; No message file for product=NETWORK, facili
    ty=TNS
    TNS-00527: Message 527 not found; No message file for product=NETWORK, facilit
    y=TNS
    Response to set is :-
    ALLUSERSPROFILE=C:\Documents and Settings\All Users
    APPDATA=C:\Documents and Settings\User1\Application Data
    CATALINA_HOME=F:\Dev\java setups\ExadelStudioPro-4.0.0\tomcat
    CLIENTNAME=Console
    CommonProgramFiles=C:\Program Files\Common Files
    COMPUTERNAME=AWAIS
    ComSpec=C:\WINDOWS\system32\cmd.exe
    FP_NO_HOST_CHECK=NO
    GDAL_DATA=C:\Program Files\PFPS\system\gdal_data
    GEOTIFF_CSV=C:\Program Files\PFPS\system\gdal_data
    GEOTRANS_DATA=C:\Documents and Settings\All Users\Application Data\PFPS\data\Geo
    Trans
    HOMEDRIVE=C:
    HOMEPATH=\Documents and Settings\User1
    JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21
    LOGONSERVER=\\AWAIS
    NUMBER_OF_PROCESSORS=2
    ODI_JAVA_HOME=D:\OraHome_1\jre\1.4.2
    ORACLE_HOME=C:\oraclexe\app\oracle\product\10.2.0
    OS=Windows_NT
    Path=C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\WINDOWS\system32;C:\WIN
    DOWS;C:\WINDOWS\System32\Wbem;C:\PROGRA~1\COMMON~1\LEADTO~1\Help;C:\PROGRA~1\LEA
    DTE~1\LEADTO~1.5\Bin\CDLL\Win32;C:\Program Files\Microsoft SQL Server\100\Tools\
    Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\PFPS\
    system;
    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
    PROCESSOR_ARCHITECTURE=x86
    PROCESSOR_IDENTIFIER=x86 Family 6 Model 15 Stepping 13, GenuineIntel
    PROCESSOR_LEVEL=6
    PROCESSOR_REVISION=0f0d
    ProgramFiles=C:\Program Files
    PROJ_LIB=C:\Program Files\PFPS\system\proj_lib
    PROMPT=$P$G
    SESSIONNAME=Console
    SystemDrive=C:
    SystemRoot=C:\WINDOWS
    TEMP=C:\DOCUME~1\User1\LOCALS~1\Temp
    TMP=C:\WINDOWS\TEMP
    USERDOMAIN=AWAIS
    USERNAME=User1
    USERPROFILE=C:\Documents and Settings\User1
    VLC_HOME=C:\Program Files\VideoLAN\VLC\
    windir=C:\WINDOWS
    and finally response to lsnrctl service is :-
    LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 27-NOV-2010 10:40
    :29
    Copyright (c) 1991, 2005, Oracle. All rights reserved.
    Message 1053 not found; No message file for product=NETWORK, facility=TNSTNS-125
    57: Message 12557 not found; No message file for product=NETWORK, facility=TNS
    TNS-12560: Message 12560 not found; No message file for product=NETWORK, facili
    ty=TNS
    TNS-00527: Message 527 not found; No message file for product=NETWORK, facilit
    y=TNS

  • Problems connecting to an Oracle database

    The service name in my pc is GACASASF and the name of the table that I'm trying to
    query is DEPT.
    Could you please tell me what's wrong with my connection, is not working.
    I think that it has something to do with the connecting string.
    I went to ODBC help for oracle connections and the connection strings that I found are
    1) DSN=Personnel;UID=Kotzwinkle;PWD=;
    2) DRIVER={Oracle ODBC Driver};UID=Kotzwinkle;PWD=whatever;DBQ=instl_alias;
    DBA=W;
    DSN=     ODBC data source name
    UID = user name
    PWD = password
    DBQ = service name
    DBA = connection mode W = write, R = read
    I don't know how to embed this in my syntax.
    I will appreciate any info that you can give me.
    thx,
    Gustavo Casasfranco
    import java.sql.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class TableDisplay extends JFrame {
    private Connection connection;
    private JTable table;
    public TableDisplay()
    // The URL specifying the Books database to which
    // this program connects using JDBC to connect to a
    // Microsoft ODBC database.
    String url = "jdbc:odbc:GACASASF";
    String username = "scott";
    String password = "tiger";
    // Load the driver to allow connection to the database
    try {
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
    connection = DriverManager.getConnection(
    url, username, password );
    catch ( ClassNotFoundException cnfex ) {
    System.err.println(
    "Failed to load JDBC/ODBC driver." );
    cnfex.printStackTrace();
    System.exit( 1 ); // terminate program
    catch ( SQLException sqlex ) {
    System.err.println( "Unable to connect" );
    sqlex.printStackTrace();
    getTable();
    setSize( 450, 150 );
    show();
    private void getTable()
    Statement statement;
    ResultSet resultSet;
    try {
    String query = "SELECT * FROM DEPT";
    statement = connection.createStatement();
    resultSet = statement.executeQuery( query );
    displayResultSet( resultSet );
    statement.close();
    catch ( SQLException sqlex ) {
    sqlex.printStackTrace();
    private void displayResultSet( ResultSet rs )
    throws SQLException
    // position to first record
    boolean moreRecords = rs.next();
    // If there are no records, display a message
    if ( ! moreRecords ) {
    JOptionPane.showMessageDialog( this,
    "ResultSet contained no records" );
    setTitle( "No records to display" );
    return;
    setTitle( "Authors table from Books" );
    Vector columnHeads = new Vector();
    Vector rows = new Vector();
    try {
    // get column heads
    ResultSetMetaData rsmd = rs.getMetaData();
    for ( int i = 1; i <= rsmd.getColumnCount(); ++i )
    columnHeads.addElement( rsmd.getColumnName( i ) );
    // get row data
    do {
    rows.addElement( getNextRow( rs, rsmd ) );
    } while ( rs.next() );
    // display table with ResultSet contents
    table = new JTable( rows, columnHeads );
    JScrollPane scroller = new JScrollPane( table );
    getContentPane().add(
    scroller, BorderLayout.CENTER );
    validate();
    catch ( SQLException sqlex ) {
    sqlex.printStackTrace();
    private Vector getNextRow( ResultSet rs,
    ResultSetMetaData rsmd )
    throws SQLException
    Vector currentRow = new Vector();
    for ( int i = 1; i <= rsmd.getColumnCount(); ++i )
    switch( rsmd.getColumnType( i ) ) {
    case Types.VARCHAR:
    currentRow.addElement( rs.getString( i ) );
    break;
    case Types.INTEGER:
    currentRow.addElement(
    new Long( rs.getLong( i ) ) );
    break;
    default:
    System.out.println( "Type was: " +
    rsmd.getColumnTypeName( i ) );
    return currentRow;
    public void shutDown()
    try {
    connection.close();
    catch ( SQLException sqlex ) {
    System.err.println( "Unable to disconnect" );
    sqlex.printStackTrace();
    public static void main( String args[] )
    final TableDisplay app = new TableDisplay();
    app.addWindowListener(
    new WindowAdapter() {
    public void windowClosing( WindowEvent e )
    app.shutDown();
    System.exit( 0 );
    * (C) Copyright 1999 by Deitel & Associates, Inc. and Prentice Hall. *
    * All Rights Reserved. *
    * DISCLAIMER: The authors and publisher of this book have used their *
    * best efforts in preparing the book. These efforts include the *
    * development, research, and testing of the theories and programs *
    * to determine their effectiveness. The authors and publisher make *
    * no warranty of any kind, expressed or implied, with regard to these *
    * programs or to the documentation contained in these books. The authors *
    * and publisher shall not be liable in any event for incidental or *
    * consequential damages in connection with, or arising out of, the *
    * furnishing, performance, or use of these programs. *

    A stack trace for the exception would be very useful!
    Anyway, perhaps you should check that the username/password specified in the code correspond to those required to access the database (username = "Kotzwinkle", password = "whatever"). Sometimes you can get away with specifying these in the ODBC data source, in which case you shouldn't pass them to the getConnection method.
    Hope this helps.

  • Problem connecting Oracle 9i Lite to Oracle 9i Database

    Hi,
    I have just started working with Oracle 9i Lite and I am having
    problems connecting to an Oracle 9i (9.0.1) database using the
    packaging wizard. I can connect ok using SQL*Plus but when I connect
    using this wizard the database is located i.e. no errors arise, but
    the database schemas and tables are not found i.e. list is not
    popluated.
    However if I try to connect to an Oracle 8i (8.1.7) database there is
    no problem and the schemas and tables are found with the list being
    popluated.
    Does anyone know what the problem could be?
    Regards
    Andrew.

    I am having a similar problem, where I couldn't connect to Oracle 8i database (817). I am getting a error message when I tried to use Packaging Wizard -> Snapshot -> Import -> Username/password and jdbc:oracle:oci8:@connect string or jdbc:oracle:thin:@host:1521:Sid
    The error message is 'No Suitable Driver. Make Sure the Proper JDBC drive for "jdbc:oracle:oci8i:@<connect string>" is in the classpath"
    I would appricated if someone can send me any help on this.
    My email address is [email protected]
    Thanks
    Joshua

  • Connecting to an Oracle database using ASP

    Hi
    I am having problems connecting to an Oracle database using ASP. I am trying to do this for a school project the school's database server is running Oracle 9i. The repository is version 6. The web server I have access to only has ASP not ASP.net. What kind of connection string would I need to be able to connect to the database?

    You do need to ensure that the Oracle client and Oracle server are compatible, but that is generally pretty easy to accomplish. Unless you are trying to cross more than one major release (i.e. 9.2 client to a 7.3.4 database), you're pretty safe there.
    You could try downloading and installing the latest 8.1.7.x Oracle ODBC driver from OTN on the machine with the 8.1.7 Oracle client (I believe the last ODBC patchset was 8.1.7.10), but I don't have particular confidence that that will solve the problem. If it doesn't, we can do an ODBC trace to focus in on the issue, but installing a new driver is a much easier process, so that probably ought to be the first step.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Problem connect to Portal with SLD

    Hi , i have problem connect the portal (7.0) whit SLD server
    The SLD server is configured in the Solution Manager.
    SLD: ctsi386nt02.ctsnx.com:sapgw00
    the check connect SLD failure. show messages.
    [Thr 4724] *  ERROR       partner 'ctsi386nt02.ctsnx.com:sapgw00' not reached
    [Thr 4724] *
    TIME        Tue May 03 14:15:29 2011
    [Thr 4724] *  RELEASE     700
    [Thr 4724] *  COMPONENT   NI (network interface)
    [Thr 4724] *  VERSION     38
    [Thr 4724] *  RC          -10
    [Thr 4724] *  MODULE      nixxi.cpp
    [Thr 4724] *  LINE        2823
    [Thr 4724] *  DETAIL      NiPConnect2
    [Thr 4724] *  SYSTEM CALL connect
    [Thr 4724] *  ERRNO       10061
    [Thr 4724] *  ERRNO TEXT  WSAECONNREFUSED: Connection refused
    [Thr 4724] *  COUNTER     25
    [Thr 4724] *
    [Thr 4724] *****************************************************************************
        Return code: RFC_FAILURE(1)
        error group: 102
        key: RFC_ERROR_COMMUNICATION

    Hi,
    User SLD - doesn't matter on name belogns to system where SLD is configured and running. SO I guess you have SLD on Solman.
    In case you didn't configured SLD on portal you have to set up on portal on visual admin choose Cluster > Server >Services > SLD Data Supplier > tab Runtime > HTTP Settings and add data of your Solman's SLD hostname port and user (SLDDUSER)
    In case of you have SLD also on portal, go to SLD page e.g. http://<hostname>:5<system_number>00/sld
    On the SLD initial page, choose Administration and in the section Server > Data Suppliers.
    add data of your Solman SLD
    Check web  http://help.sap.com/saphelp_nw70/helpdata/en/ee/74b3407e73c57fe10000000a1550b0/frameset.htm
    Best regards,
    Peter

  • Mildet connect to oracle DB using servlet problem ,help please

    hi guys i have a problem am tring to connect my midlet to databse through midlet but i don`t know what is the problem so far the midlet already connect to my servlet url but the servlet cant read the parameters to open the connection for database
    my servlet code
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    import java.io.*;
    import java.net.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.text.*;
    * @author freddy
    public class getconnection extends HttpServlet {
        Statement statement;
    ResultSet rs=null;
    String bstr=null;
    String bstr1=null;
    String bstr2=null;
    public void init()
        * 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, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            try {
                /* TODO output your page here
                out.println("<html>");
                out.println("<head>");
                out.println("<title>Servlet getConnection</title>"); 
                out.println("</head>");
                out.println("<body>");
                out.println("<h1>Servlet getConnection at " + request.getContextPath () + "</h1>");
                out.println("</body>");
                out.println("</html>");
            } finally {
                out.close();
        // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
        * Handles the HTTP <code>GET</code> method.
        * @param request servlet request
        * @param response servlet response
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
      doPost(request,response);
        * Handles the HTTP <code>POST</code> method.
        * @param request servlet request
        * @param response servlet response
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
            DataInputStream in = new DataInputStream(
                    (InputStream)request.getInputStream());
            String sid = in.readUTF();
            String user = in.readUTF();
            String pwd = in.readUTF();
          //  "jdbc:oracle:thin:@localhost:1521"+": "+sid
            String message = message = "Name:"+bstr+" telephone:"+bstr1+" burthday:"+bstr2;
             try {
                connect(sid,user, pwd);
                message += "100 ok connected";
            } catch (Throwable t) {
                message += "200 " + t.toString();
            response.setContentType("text/plain");
            response.setContentLength(message.length());
            PrintWriter out = response.getWriter();
            out.println(message);
            in.close();
            out.close();
            out.flush();
        private void connect(String sid, String user,String pwd)
        throws Exception {
            // Establish a JDBC connection to the MYSQL database server.
            //Class.forName("org.gjt.mm.mysql.Driver");
            Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
            Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:"+sid,user,pwd);
            System.out.print("connected");
            try{
               statement =conn.createStatement();
                rs=statement.executeQuery(" Select*from WOH.P_DEMGRAPHICS where P_ID='P1000 '");
            catch(SQLException e)
            System.err.print(e);
           try{
    while (rs.next()) {
    bstr=rs.getString(2);
    bstr1=rs.getString(3);
    bstr2=rs.getString(4);
    statement.close();
       catch (SQLException e) {
    //bstr += e.toString();
    System.err.println(e);
    System.exit(1);
            // Establish a JDBC connection to the Oracle database server.
            //DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
            //Connection conn = DriverManager.getConnection(
            //      "jdbc:oracle:thin:@localhost:1521:"+db,user,pwd);
            // Establish a JDBC connection to the SQL database server.
            //Class.forName("net.sourceforge.jtds.jdbc.Driver");
            //Connection conn = DriverManager.getConnection(
            //      "jdbc:jtds:sqlserver://localhost:1433/"+db,user,pwd);
        * Returns a short description of the servlet.
        public String getServletInfo() {
            return "Short description";
        // </editor-fold>
    }Midlet code
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    import java.io.*;
    import java.util.*;
    import javax.microedition.io.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    * @author freddy
    public class testOrcl extends MIDlet  implements CommandListener {
       protected String url;
        private String username;
        private Display display;
        private Command exit = new Command("EXIT", Command.EXIT, 1);;
        private Command connect = new Command("Connect", Command.SCREEN, 1);
        private TextField tb;
        private Form menu;
        private TextField tb1;
        private TextField tb2;
        DB db;
        public testOrcl() throws Exception
            display=Display.getDisplay(this);
            url="http://localhost:8084/getConnection/getconnection";
        public void startApp() {
            displayMenu();
        public void displayMenu()
        menu= new Form("connect");
         tb = new TextField("Please input database: ","",30,
                    TextField.ANY );
            tb1 = new TextField("Please input username: ","",30,
                    TextField.ANY);
            tb2 = new TextField("Please input password: ","",30,
                    TextField.PASSWORD);
            menu.append(tb);
            menu.append(tb1);
            menu.append(tb2);
            menu.addCommand(exit);
            menu.addCommand(connect);
            menu.setCommandListener(this);
            display.setCurrent(menu);
        public void pauseApp() {
        public void destroyApp(boolean unconditional) { }
        public void commandAction(Command command, Displayable screen) {
            if (command == exit) {
                destroyApp(false);
                notifyDestroyed();
            } else if (command == connect) {
                db  = new DB(this);
                db.start();
                db.connectDb(tb.getString(),tb1.getString(),tb2.getString());
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    import java.io.*;
    import java.util.*;
    import javax.microedition.io.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.lang.*;
    * @author freddy
    public class DB implements Runnable  {
        testOrcl midlet;
         private Display display;
            String sid;
            String user;
            String pwd;
            public DB( testOrcl midlet)
            this.midlet=midlet;
            display=Display.getDisplay(midlet);
        public void start()
        Thread t = new Thread(this);
                t.start();
        public void run()
         StringBuffer sb = new StringBuffer();
                try {
                    HttpConnection c = (HttpConnection) Connector.open(midlet.url);
                   c.setRequestProperty(
                       "User-Agent","Profile/MIDP-2.1, Configuration/CLDC-1.1");
                    c.setRequestProperty("Content-Language","en-US");
                    c.setRequestMethod(HttpConnection.POST);
                    DataOutputStream os =
                            (DataOutputStream)c.openDataOutputStream();
                    os.writeUTF(sid.trim());
                    os.writeUTF(user.trim());
                    os.writeUTF(pwd.trim());
                    os.flush();
                    os.close();
                    // Get the response from the servlet page.
                    DataInputStream is =(DataInputStream)c.openDataInputStream();
                    //is = c.openInputStream();
                    int ch;
                    sb = new StringBuffer();
                    while ((ch = is.read()) != -1) {
                        sb.append((char)ch);
               showAlert(sb.toString());
                    is.close();
                    c.close();
                } catch (Exception e) {
                    showAlert(e.getMessage());
         /* This method takes input from user like db,user and pwd and pass
                to servlet */
            public void connectDb(String sid,String user,String pwd) {
                this.sid = sid;
                this.user = user;
                this.pwd = pwd;
            /* Display Error On screen*/
            private void showAlert(String err) {
                Alert a = new Alert("");
                a.setString(err);
                a.setTimeout(Alert.FOREVER);
                display.setCurrent(a);
       

    Comment out process request or rewrite & move it to a position after you read the parameters and connect to the db. Decide where you want to write to the output stream. Also, you have some superfluous casting.
    I take it that you are using netbeans? If you debug and step through the code you will get an idea of the flow. The steps should be, midlet connects with POST, doPost is called, server reads parameters, server opens connection, executes query, releases/closes connection, and writes a response to the midlet.
    Some notes about the connect method; The scope of rs may cause problems. It is unlike you will have a valid result set if you have a problem with create statement or execute. Take a look at connection pooling and be mindful how the connections are opened, used, and closed; put all the important cleanup operations in a finally. Remove system.exit from your servlet. Actually I would suggest limiting the scope of all your vars;
    If you store the username, password, and sid on the midlet, you may have trouble updating the installation base if you need to change the values for any reason. Also, you have clients which contain your database u/p, susceptible to snooping and decompilation. Use the servlet to abstract the db from the client. And use a datasource (with connection pooling) for obtaining connections to db.

  • Problem in connecting JSP with Oracle 9i.

    Hi,
    I am having problem in connecting JSP with Oracle 9i.
    I am using windows XP and my JDK version is 1.4. For executing JSP I am using
    "jakarta-tomcat-5.5.4-preconfigured". My database name is global.
    I have set java_home, j2ee_home, oracle_home, path, classpath as follows:
    j2ee_home=c:\sun\appserver
    java_home=c:\sun\appserver\jdk
    oracle_home=C:\oracle\ora92
    path=C:\Sun\AppServer\bin;C:\Sun\AppServer\jdk\bin;C:\oracle\ora92\bin
    classpath=C:\Sun\AppServer\lib\j2ee.jar;C:\oracle\ora92\jdbc\lib\ojdbc14.jar;C:\oracle\ora92\jdbc\lib\nls_charse
    t12.zip
    My code is as follows:
    <%@ page language="java" %>
    <%@ page import ="java.sql.*"%>
    <%
    try
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    Connection conn = DriverManager.getConnection ("jdbc:oracle:oci8:@global", "scott", "tiger");
    catch(SQLException e)
    out.println(""+e);
    out.println("Connected");
    %>
    I tried other program:
    <%@ page language="java" %>
    <%@ page import ="java.sql.*"%>
    <%
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:global","scott","tiger");
    out.println("Connected");
    %>
    I am getting following error:
    exception
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 5 in the jsp file: /jsp/oracle.jsp
    Generated servlet error:
    oracle.jdbc.OracleDriver cannot be resolved or is not a type
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
         org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:389)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    Thanking you in advance,
    Anurag

    maneesh108 wrote:
    hi this is maneesh1) Read the thread it has been answered.
    2) The thread is very old. Don't resurrect old threads.
    I'm locking this zombie thread.
    Kaj

  • I am having problems connecting to home wifi.  It was working, but now all I get is a blank white screen.  I re-booted with no success.

    I am having problems connecting to home wifi.  It was working, but now all I get is a blank white screen.  I re-booted with no success.

    Hi, blank white screen where exactly?
    Make a New Location, Using network locations in Mac OS X ...
    http://support.apple.com/kb/HT2712
    10.5, 10.6, 10.7 & 10.8…
    System Preferences>Network, top of window>Locations>Edit Locations, little plus icon, give it a name.
    10.5.x/10.6.x/10.7.x/10.8.x instructions...
    System Preferences>Network, click on the little gear at the bottom next to the + & - icons, (unlock lock first if locked), choose Set Service Order.
    The interface that connects to the Internet should be dragged to the top of the list.
    If using Wifi/Airport...
    Instead of joining your Network from the list, click the WiFi icon at the top, and click join other network. Fill in everything as needed.
    For 10.5/10.6/10.7/10.8, System Preferences>Network, unlock the lock if need be, highlight the Interface you use to connect to Internet, click on the advanced button, click on the DNS tab, click on the little plus icon, then add these numbers...
    208.67.222.222
    208.67.220.220
    (There may be better or faster DNS numbers in your area, but these should be a good test).
    Click OK.

Maybe you are looking for

  • My ipod is not recognized by itunes. Menus missing in itunes.

    After I updated my ipod and my itunes, now the ipod is not recognized in itunes.  I went through all the recommended steps; starting and stopping various programs on my control panel, turning ipod on and off, checking cables - everything short of sta

  • Return after PDF display

    I have a BSP that generates a PDF from a smartform when the user clicks a button, returns it as an XSTRING, and displays it, based on notes i found on other threads here. The smartform comes up fine, but when i close the page with the PDF displayed,

  • DPP Digital Photo Professional and Flickr

    hi there... on begin i want t osay sorry for my not  precise speling.. im DPP user and lover...i was think of  come to this forum long ago but like it happend i was late so im now .. ok ..my point its DPP Software... on Flickr there is Group where pe

  • Apple Mail on MacBook Air 10.10.3

    Mailbox behavior: when I 'renamed' a mailbox, then all of the messages I had stored under the previous name vanished; did I delete these through this action?

  • Ghosting with External CRT Monitor. Any Solution Yet?

    a number of months ago i saw a LONG thread that, as far as i read, never really solved this issue. I was wondering if a solution was ever found. thanks, seth