Jdbc-servlet help!!!!!!!!

excuse my english.
hey folks, i got this problem:
i`m trying to do a simple servlet that`s throw a html with a result, but i always got this error:
java.lang.NullPointerException
at ConsultaServlet.doPost(ConsultaServlet.java:45)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
THIS IS THE CODE I HAVE:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HolaServlet extends HttpServlet {
private Connection con;
private PrintWriter out;
private Statement stmt;
public void init(ServletConfig conf)
throws ServletException {
super.init(conf);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con =DriverManager.getConnection("jdbc:odbc:MS Access Database");
}catch(Exception e) {
System.err.println(e);
public void service(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
try {   
out = res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title> Sample JDBC Servlet Demo" +
"</title>");
out.println("</head>");
out.println("<body>");
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from empleados");
out.println("<UL>");
while(rs.next()) {
out.println("<LI>" + rs.getString("nombre"));
out.println("</UL>");
rs.close();
stmt.close();
} catch(SQLException e) {
out.println("An SQL Exception was thrown.");
} catch(IOException e) {
System.err.println("An IOException was thrown.");
out.println("</body>");
out.println("</html>");
out.close();
public void destroy(){
try{
con.close();
}catch(SQLException e) {
Can someone tell me what i`m doing wrong.
THANK.

Hi,
I have intalled the Javawebserver2.0
Its been installed on C:\javawebserver2.0.
After this I have set the autoexec.bat path as
PATH C:\WINDOWS;C:\WINDOWS\COMMAND;C:\ORAWIN95\bin;c:\Oracle\Ora81\bin;"C:\ProgramFiles\Oracle\jre\1.1.7\bin";c:\j2sdk1.4.2_04\bin;c:\JavaWebServer2.0\bin;c:\Jsdk2.0\bin
rem - By Windows 98 Network for Netware Upgrade - c:\windows\odihlp.exe
set classpath=.;c:\j2dsk1.4.2_04\jre\lib;c:\j2dsdk1.4.2_04\lib;c:\j2sdk1.4.2_04\bin;c:\JavaWebServer2.0\lib;c:\Jsdk2.0\lib
rem -;c:\jsdk2.1\src ;c:\jsdk2.1\lib;c:\Jsdk2.0\src
After doing this I wrote my first servlet program in the servlets directory of javawebserver2.0 saved and when I went to compile its not compiling throwing an error showing that it is unable to locate all the servlet packages. So in I thought might be there are 2 things one is either I have not imported javax.servlet.* and javax.servlet.httpServlet.* package, but I had included it, the next thing was to check the autoexec.bat path. I included in that javawebserver2.0 path. Now first I am not able to compile the servlet program. Can you help me with it.
I had downloaded jsdk2 from net and have given its path also in the autoexec but nothing is happening. I am using the following package to write and develop Java programs "j2sdk1.4.2_04". Can you explain to where I am going wrong. Please its a bit urgent.
Following is the program:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class helloWorld extends HttpServlet
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html>");
out.println("<head><Title>Hello World</title></head>");
out.println("<body><big>Hello World</big>");
out.println("</body>");
out.println("</html>");
Help!!!!!!!!

Similar Messages

  • JDBC URL helper class

    Hi,
    Was trying use third party(Caucho) jdbc type 4 driver for MySQL. I updated the
    jdbcdrivers.xml to include the details for the new driver. However, when using
    Config wizard, how (or where) do i provide a JDBC url helper class, so that the
    config wizard can connect the database using the jdbc url?
    Amit.

    Amit wrote:
    Joe Weinstein <[email protected]> wrote:
    Actually, all you need to do is get the driver you want into the weblogic
    classpath, and then tell the pool the class name you want for the driver,
    and give it the URL and properties it needs.
    Joe
    Hi. In order to implement a custom default, you would need to have
    a URLHelper class, as the other entries refer. I don't know that we
    offer a way to create Defaults, but you should be able to create a pool
    from the console by specifically typing in the class name and the URL.
    Is that not true?
    Joe
    >
    >
    Thanks Joe,
    But i wanted to see the jdbc url changed in the config wizard screen (as pointed
    in the pic). Caucho jdbc driver has url like "jdbc:mysql-caucho://hostname:port/database".
    Others mysql drivers have url like "jdbc:mysql://hostname:port/database. So where
    exactly could i tweek that property, since all that is editable is hostname, port,
    and database?

  • WAP/Servlet help is needed URGENT!!!

    I've wrote this little wap-application, which update the library loans via mobile phones. I don't know why my login doesn't work properly (it gives error-messages in any cases). I believe I did everything right.
    Can anyone PLEASE help me finding my mistakes!? I give all my dukes for working version of mine application.
    This are my codes:
    Servlet-class
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    public class Uusinta extends HttpServlet {
    Connection conn;
    String TUNNUS = "2000000112222";
    String user = null;
    boolean yhteys = false;
    static String [] otsikko = {
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>",
    "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.3//EN\" \"http://www.wapforum.org/DTD/wml13.dtd\"> " ,
    "<wml>" ,
    "<!-- Possible <head> elements here. --> " ,
    "<template>" ,
    "<do type=\"accept\" label=\"Ok\" name=\"back\" >" ,
    "<prev/>" ,
    "</do>" ,
    "</template>" ,
    "<card id=\"welcome\" title=\"WAP-kirjasto\" newcontext=\"true\">" ,
    "<do type=\"accept\" name=\"back\"><noop/>" ,
    "</do>" ,
    "<p align=\"center\"><strong>TERVETULOA</strong></p>",
    "<p><br/>Kirjastokortin numero:<br/>" ,
    "<input type=\"text\" name=\"numero\" size=\"11\" format=\"*N\" maxlength=\"13\"/><br/>" ,
    "Salasana:<br/>" ,
    "<input type=\"text\" name=\"salasana\" size=\"4\" format=\"*N\" maxlength=\"4\"/><br/>" ,
    "<a href=\"skripti.wmls#Login('$(numero)','$(salasana)','kayttaja')\">Sisaan </a></p>" ,
    "</card>" ,
    "<card id=\"loginError\">" ,
    "<do type=\"prev\" label=\"Back\">" ,
    "<go href=\"#welcome\"/>" ,
    "</do>" ,
    "<p align=\"center\"><br/>Korttinumero tai salasana on vaara.</p>" ,
    "</card>" ,
    "<card id=\"lainat\" newcontext=\"true\">" ,
    "<do type=\"accept\" name=\"back\"><noop/>" ,
    "</do>" ,
    "<do type=\"options\" label=\"Lopeta\">" ,
    "<go href=\"#goodbye\"/>" ,
    "</do>" ,
    "<p><b>Lainatut kirjat:</b></p><p> " ,
    "<select name=\"item\" title=\"Lista\">"};
    static String [] r2 = {
    "</select>" ,
    "<br/><a href=\"skripti.wmls#uusiNide('$(item)','valittu')\">Uusi valittu</a><br/>" ,
    "<a href=\"skripti.wmls#uusiKaikki()\">Uusi kaikki</a></p>" ,
    "</card>" ,
    "<card id=\"virhe\">" ,
    "<p>Kirjan uusiminen ei onnistunut. Yrit&#xE4; uudelleen.</p>" ,
    "</card>" ,
    "<card id=\"uusittu\">" ,
    "<do type=\"prev\" label=\"Back\">",
    " <go href=\"#lainat\"/>",
    "</do>",
    "<p align=\"center\"><br/>Kirja on uusittu.</p>" ,
    "</card>" ,
    "<card id=\"virheet\">" ,
    "<p>Kirjojen uusiminen ei onnistunut. Yrit&#xE4; uudelleen.</p>" ,
    "</card>" ,
    "<card id=\"uusitut\">" ,
    "<do type=\"prev\" label=\"Back\">",
    " <go href=\"#goodbye\"/>",
    "</do>",
    "<p align=\"center\"><br/>Kirjat on uusittu.</p>" ,
    "</card>" ,
    "<card id=\"goodbye\" newcontext=\"true\">" ,
    "<do type=\"accept\" name=\"back\"><noop/>" ,
    "</do>" ,
    "<p align=\"center\"><br/>Kiitos k�ynnist�. Ja tervetuloa uudelleen.</p>" ,
    "</card>" ,
    "</wml>"};
    private void teeWML(PrintWriter out)
    Statement stmt;
    ResultSet result;
    boolean ok = false;
    for (int i = 0; i <otsikko.length;i++)
         out.println(otsikko);
         if(yhteys)
    try {
    stmt= conn.createStatement();
    result = stmt.executeQuery("Select * FROM lainat l join kirja k on l.nide = k.nide where tunnus = '"+this.user+"'");
    int cnt = 1;
    while(result.next())
              ok = true;
                   String nimi ="";
         if(result.getString("nimi").length() > 8)
         nimi = result.getString("nimi").substring(0,8) + "...";
         else
         nimi = result.getString("nimi");
              out.println("<option value=\""+result.getString("l.nide")+"\">"+nimi+":"
              result.getString("erapaiva")"</option>");
    result.close();
    stmt.close();
    }catch (SQLException ex) {
    System.out.println ("\nSQLException:");
    while (ex != null) {
    System.out.println ("SQLState: "+ ex.getSQLState());
    System.out.println ("Message: "+ ex.getMessage());
    System.out.println ("Vendor: "+ ex.getErrorCode());
    ex = ex.getNextException();
    else
              out.println("<option value=\"0\">nothing</option>");
         for (int i = 0; i <r2.length;i++)
              out.println(r2[i]);
    out.close();
    private void uusiNide(PrintWriter out, String nide)
    Statement stmt;
    ResultSet result;
    boolean ok=false;
         try {
    stmt= conn.createStatement();
    result = stmt.executeQuery("Select nide from lainat where tunnus='"+user+"' ");
    int cnt = 1;
    while(result.next())
              ok = true;
    result.close();
    stmt.close();
         if(ok)
              String pvm = getPvm();
              stmt = conn.createStatement();
              int a = stmt.executeUpdate("update lainat set erapaiva='"+pvm+"' where tunnus='"+user+"' AND nide='"+nide+"'");
    }catch (SQLException ex) {
    System.out.println ("\nSQLException:");
    while (ex != null) {
    System.out.println ("SQLState: "+ ex.getSQLState());
    System.out.println ("Message: "+ ex.getMessage());
    System.out.println ("Vendor: "+ ex.getErrorCode());
    ex = ex.getNextException();
         if(ok) {
         out.println("<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">");
              out.println("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><title>koe</title></head><body><p>OKnide</p></body></html>");
    private void uusiKaikkiNiteet(PrintWriter out)
    Statement stmt;
    ResultSet result;
    boolean ok=false;
    //t�h�n tulee viel� korttinumero
         try {
              String pvm = getPvm();
         stmt = conn.createStatement();
              int a = stmt.executeUpdate("update lainat set erapaiva='"+pvm+"' where tunnus='"+user+"'");
    }catch (SQLException ex) {
    System.out.println ("\nSQLException:");
    while (ex != null) {
    System.out.println ("SQLState: "+ ex.getSQLState());
    System.out.println ("Message: "+ ex.getMessage());
    System.out.println ("Vendor: "+ ex.getErrorCode());
    ex = ex.getNextException();
    if(ok) {
              out.println("<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">");
              out.println("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><title>koe</title></head><body><p>OKKaikki</p></body></html>");
    private void tarkKayttaja(PrintWriter out, String kayttaja, String password)
    Statement stmt;
    ResultSet result;
    boolean ok=false;
    String nimi = null;
    if(user !=null && password !=null)
    int salasana = Integer.parseInt(password);
    try {
    stmt= conn.createStatement();
    result = stmt.executeQuery("Select * from kortti where numero='"+kayttaja+"' and salasana="+salasana);
    while(result.next())
              ok = true;
              nimi = result.getString("nimi");
    }catch (SQLException ex) {
         System.out.println ("\nSQLException:");
         while (ex != null) {
         System.out.println ("SQLState: "+ ex.getSQLState());
         System.out.println ("Message: "+ ex.getMessage());
         System.out.println ("Vendor: "+ ex.getErrorCode());
         ex = ex.getNextException();
         if(ok) {
                   this.user= kayttaja;
                   yhteys = true;
                   //teeWML(out);
         out.println("<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">");
              out.println("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><title>koe</title></head><body><p>OK</p></body></html>");
              //out.close();
         teeWML(out);
    public void init(ServletConfig cfg) throws ServletException
    try{
    Driver d = (Driver)Class.forName("com.mysql.jdbc.Driver").newInstance();
    String sCon = "jdbc:mysql://localhost/kirjasto?user=oppilas&password=oppix";
    conn = DriverManager.getConnection(sCon);
    }catch(Exception e){
    System.out.println ("Exception: "+ e.getMessage());
    throw new ServletException(e.getMessage());
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws IOException, ServletException
    PrintWriter out = null;
         String kutsu = req.getParameter("toiminto");
         String uusinta = req.getParameter("uusinta");
         String password = req.getParameter("password");
         String kayttaja = req.getParameter("user");
         if (kutsu == null) {
         res.setContentType("text/vnd.wap.wml");
         out = res.getWriter();
              tarkKayttaja(out, null, null);
         if(kutsu.equalsIgnoreCase("login")) {
         res.setContentType("text/html");
         out = res.getWriter();
              tarkKayttaja(out, kayttaja, password);
         if(kutsu.equalsIgnoreCase("uusi")) {
         res.setContentType("text/html");
         out = res.getWriter();
              uusiNide(out, uusinta);
         if(kutsu.equalsIgnoreCase("uusiKaikki")){
              res.setContentType("text/html");
              out = res.getWriter();
              uusiKaikkiNiteet(out);
    public void destroy()
    try{
    conn.close();
    }catch(SQLException e){
    System.out.println ("\nSQLException:");
    System.out.println ("SQLState: "+e.getSQLState());
    System.out.println ("Message: "+ e.getMessage());
    System.out.println ("Vendor: "+ e.getErrorCode());
    public String getPvm()
         Calendar x = Calendar.getInstance();
         x.add(Calendar.DATE, 30);
              int Day = x.get(Calendar.DAY_OF_YEAR);
              Day = Day+30;
              x.set(Calendar.DAY_OF_YEAR, Day);
              int monthDue = x.get(Calendar.MONTH);
              int dayOfMonthDue = x.get(Calendar.DAY_OF_MONTH);
              int yearDue = x.get(Calendar.YEAR);
                   System.out.println(yearDue+"-"+monthDue+"-"+dayOfMonthDue);
              return (yearDue+"-"+monthDue+"-"+dayOfMonthDue);
    skriptit.wmls
    extern function uusiNide(prmIn,valittu) {
         var str, result, okInd, pInd;
         str = "http://localhost:8080/kirjasto/loans?toiminto=uusi&uusinta=" +URL.escapeString(prmIn);
         var load = URL.loadString(str,"text/html");
         okInd =String.find(load, "OKnide");
         if( okInd != -1 ) {
              result = WMLBrowser.setVar(valittu, prmIn);
              WMLBrowser.go("#uusittu");
         else {
              WMLBrowser.go("#virhe");
         return "";
    extern function uusiKaikki() {
         var str, result, okInd, pInd, val, valittu;
         str = "http://localhost:8080/kirjasto/loans?toiminto=uusiKaikki&uusinta=";
         var load = URL.loadString(str,"text/html");
         okInd =String.find(load, "OKKaikki");
         if( okInd != -1 ) {
              WMLBrowser.go("#uusitut");
         else {
              WMLBrowser.go("#virheet");
         return "";
    extern function Login(prmNum, prmPass, kayttaja) {
         var str, result, okInd, pInd, pos, nimi;
         str = "http://localhost:8080/kirjasto/loans?toiminto=login&user="+URL.escapeString(prmNum)+"&password="+URL.escapeString(prmPass);
         var load = URL.loadString(str,"text/html");
         okInd =String.find(load, "OK");
         if( okInd != -1 ) {     
              pos = String.find(load, "</p");
              nimi = String.subString(load,(okInd + 7), (pos - okInd -7));
              result = WMLBrowser.setVar(kayttaja, nimi);
              WMLBrowser.go("#lainat");
         else {
              WMLBrowser.go("#loginError");
         return "";
    web.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
    'http://java.sun.com/j2ee/dtds/web-app_2_3.dtd'>
    <web-app>
    <display-name>Verkkopizzeria</display-name>
    <servlet>
    <servlet-name>Vastaa</servlet-name>
    <servlet-class>Vastaa</servlet-class>
    </servlet>
    <servlet>
    <servlet-name>Uusinta</servlet-name>
    <servlet-class>Uusinta</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Vastaa</servlet-name>
    <url-pattern>/vastaa</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>Uusinta</servlet-name>
    <url-pattern>/loans</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    </web-app>
    DB create and inserts
    create table kortti(
    numero char(13) not null,
    nimi char(25),
    osoite char(25),
    postinro int(5),
    puhelin char(15),
    salasana int(4),
    primary key(numero)
    create table kirja(
    nide char(10) not null,
    nimi char(25) not null,
    tekija char(25) not null,
    vuosi int(4) not null,
    primary key(nide)
    create table lainat(
    tunnus char(13) not null,
    nide char(10) not null,
    erapaiva date not null,
    primary key (tunnus, nide),
    foreign key (tunnus) references kortti,
    foreign key (nide) references kirja );
    insert into kortti
    (numero, nimi, osoite, postinro, puhelin, salasana)
    values
    ('2000000112222', 'Aku Ankka', 'Akunkatu 11', 00980, '0401231234', 2222);
    insert into kortti
    (numero, nimi, osoite, postinro, puhelin, salasana)
    values
    ('2000000113333', 'Roope Set�', 'Mikonkatu 11', 00100, '0405552223', 3333);
    insert into kortti
    (numero, nimi, osoite, postinro, puhelin, salasana)
    values
    ('2000000114444', 'Mikki Hiiri', 'Kissankuja 5', 00930, '04009876545', 4444);
    insert into kortti
    (numero, nimi, osoite, postinro, puhelin, salasana)
    values
    ('2000000115555', 'Ville Vallaton', 'Mestarinrinne 4', 00310, '0952223335', 5555);
    insert into kirja
    (nide, nimi, tekija, vuosi)
    values
    ('1111-85555','Wap', 'Pekka Niskanen', 2000);
    insert into kirja
    (nide, nimi, tekija, vuosi)
    values
    ('1111-45345','Java 2', 'Pekka Niskanen', 2002);
    insert into kirja
    (nide, nimi, tekija, vuosi)
    values
    ('1111-64648','J�rki ja tunteet', 'Jane Austin', 1998);
    insert into kirja
    (nide, nimi, tekija, vuosi)
    values
    ('1111-15671','Rikos ja rangastus', 'Leo Tolstoy', 1998);
    insert into kirja
    (nide, nimi, tekija, vuosi)
    values
    ('1111-85554','Inside Wap', 'Pekka Niskanen', 2002);
    insert into lainat
    (tunnus, nide, erapaiva)
    values
    ('2000000112222', '1111-85555', '2004-5-01-11');
    insert into lainat
    (tunnus, nide, erapaiva)
    values
    ('2000000112222', '1111-45345', '2004-5-01-11');
    insert into lainat
    (tunnus, nide, erapaiva)
    values
    ('2000000112222', '1111-64648', '2004-5-01-12');
    insert into lainat
    (tunnus, nide, erapaiva)
    values
    ('2000000113333', '1111-85554', '2004-5-01-11');
    insert into lainat
    (tunnus, nide, erapaiva)
    values
    ('2000000114444', '1111-15671', '2004-5-01-12');

    So many things wrong with this post... from [url http://www.catb.org/~esr/faqs/smart-questions.html#urgent]How to Ask Questions the Smart Way:
    Don't flag your question as ?Urgent?, even if it is for you
    That's your problem, not ours. Claiming urgency is very likely to be counter-productive: most hackers will simply delete such messages as rude and selfish attempts to elicit immediate and special attention.
    There is one semi-exception. It can be worth mentioning if you're using the program in some high-profile place, one that the hackers will get excited about; in such a case, if you're under time pressure, and you say so politely, people may get interested enough to answer faster.
    This is a very risky thing to do, however, because the hackers' metric for what is exciting probably differ from yours. Posting from the International Space Station would qualify, for example, but posting on behalf of a feel-good charitable or political cause would almost certainly not. In fact, posting ?Urgent: Help me save the fuzzy baby seals!? will reliably get you shunned or flamed even by hackers who think fuzzy baby seals are important.
    If you find this mysterious, re-read the rest of this how-to repeatedly until you understand it before posting anything at all.
    Be precise and informative about your problem
    Describe the symptoms of your problem or bug carefully and clearly.
    Describe the environment in which it occurs (machine, OS, application, whatever). Provide your vendor's distribution and release level (e.g.: ?Fedora Core 1?, ?Slackware 9.1?, etc.).
    Describe the research you did to try and understand the problem before you asked the question.
    Describe the diagnostic steps you took to try and pin down the problem yourself before you asked the question.
    Describe any recent changes in your computer or software configuration that might be relevant.
    Do the best you can to anticipate the questions a hacker will ask, and to answer them in advance in your request for help.
    Simon Tatham has written an excellent essay entitled How to Report Bugs Effectively. I strongly recommend that you read it.
    Volume is not precision
    You need to be precise and informative. This end is not served by simply dumping huge volumes of code or data into a help request. If you have a large, complicated test case that is breaking a program, try to trim it and make it as small as possible.
    This is useful for at least three reasons. One: being seen to invest effort in simplifying the question makes it more likely that you'll get an answer, Two: simplifying the question makes it more likely you'll get a useful answer. Three: In the process of refining your bug report, you may develop a fix or workaround yourself
    And from [url http://www.thejword.com]The J Word:
    Code Tags
    When you post code, please use [code] and [/code] tags as described in Formatting Help on the message entry page. It makes it much easier to read.

  • JDBC Servlet Problem

    Hi,
    I am trying to write a servlet to do a simple query against a database, however I am getting an "ERROR 405 - Resource not allowed".
    I am getting nothing appearing in my webservers or the jdbc log, so I don't have a stack trace to show you all.
    Any help would be appreaciated!!
    Code Below (certain data removed for security):
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.sql.ResultSet.*;
    import java.util.*;
    import java.util.Arrays;
    public class Mitch extends HttpServlet
      private Connection connection;
      private Statement statement;
      public static ArrayList Array = new ArrayList();
        public void init( ServletConfig config ) throws ServletException
            try
                String username = "xxxxxxx";
                String password = "xxxxxxx";
                Class.forName("com.ibm.db2.jcc.DB2Driver");
                String dbURL = "jdbc:db2://IP ADDRESS AND PORT/DIR";
                Properties conProps = new Properties();
                conProps.setProperty( "user", username );
                conProps.setProperty( "password", password );
                connection = DriverManager.getConnection( dbURL, conProps );
                statement = connection.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,  ResultSet.CONCUR_UPDATABLE );
           catch( Exception exception )
               exception.printStackTrace();
               throw new UnavailableException( exception.getMessage() );
        }//end init
        protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
            response.setContentType( "text/html" );
            PrintWriter out = response.getWriter();
            out.println( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n" );
            out.println( "<HTML>\n<HEAD>" );
            String sqlQuery;
            try
                sqlQuery = "SELECT h5_cpu_usr FROM ps_h5_cpu_fs_ap1 WHERE h5_dttm_stamp BETWEEN '2005-2-20 00:00:00.00000' AND '2005-2-20 23:00:00.000000'";
                ResultSet resultSet = statement.executeQuery( sqlQuery );
                out.println( "<TITLE> Servlet DB Test by Mitch </TITLE>" );
                out.println( "</HEAD>" );
                out.println( "<BODY>" );
                out.println( "<P>This is a test to connect to a database, execute a simple SELECT and display the results below." );
                out.println( "<br>\n<br>" );
                Integer intObject;
                while ( resultSet.next() )
                   intObject = new Integer( resultSet.getInt( 1 ) );   
                   Array.add( intObject );
                resultSet.close();
                for( int i = 0; i < Array.size(); i++)
                 out.println(Array.get(i));
                out.close();
            }//end try
            catch ( SQLException sqlEx )
                sqlEx.printStackTrace();
                out.println( "<TITLE>ERROR</TITLE>" );
                out.println( "<HEAD>" );
                out.println( "<BODY><P>An error occurred.<br>Contact Mitch!" );
                out.println( "</P></BODY></HTML>" );
                out.close();
        }//doPost end
        public void destroy()
            try
                statement.close();
                connection.close();
            catch( SQLException sqlEx )
                sqlEx.printStackTrace();
        }//end destroy
    }//end Class
           

    Thank you both for your replies
    1. Yes I did.
    2 See below
    I found some sample code that I adapted to my code. I removed the init( ) method and used a doGet ( ) to call my doPost ( ) method.
    The servlet now works!
    Except for one thing...
    It doesn't seem to be threading!
    I did a simple test where two different users attempted to use the servlet at the same time, the results simply added to each other. The current query I am doing is one that returns approximately 100 rows and 1 column of 2-digit integers.
    For example:
    User 1 runs the servlet, output is:
    12 45 56 66 65 23 06 03 34 56 78
    User 2 runs the servlet after User 1, output is:
    12 45 56 66 65 23 06 03 34 56 78 12 45 56 66 65 23 06 03 34 56 78
    User 1 runs servlet again, after User 2, output is:
    12 45 56 66 65 23 06 03 34 56 78 12 45 56 66 65 23 06 03 34 56 78 12 45 56 66 65 23 06 03 34 56 78
    I hope this illustrates my problem clearly.
    Also, I checked the database to see how many connections were open -- the servlet opens a NEW connection for EVERY query. These connections do not die until I kill my WebApp (WebLogic). It truely is a messy situation.
    Any help would be appreaciated for this servlet newbie.
    Thanks in advance.
    New Code:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.sql.ResultSet.*;
    import java.util.*;
    import java.util.Arrays;
    public class Mitch extends HttpServlet
      public static ArrayList Array = new ArrayList();
      Connection connection;
      Statement statement;
      String username = "xxxxxxx";
      String password = "xxxxxxx";
        protected synchronized void doGet(  HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
          doPost ( request, response );
        protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
            //HttpSession session = request.getSession(true);
            response.setContentType( "text/html" );
            PrintWriter out = response.getWriter();
            out.println( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n" );
            out.println( "<HTML>\n<HEAD>" );
            String sqlQuery;
            //if(session.isNew())
            try
                Class.forName("com.ibm.db2.jcc.DB2Driver");
                String dbURL = "jdbc:db2://xx.xx.xx.xx:yyyyy/zzzzzzz";
                connection = DriverManager.getConnection( dbURL, username, password );
                statement = connection.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,  ResultSet.CONCUR_UPDATABLE );
                sqlQuery = "SELECT h5_cpu_usr FROM ps_h5_cpu_fs_ap1 WHERE h5_dttm_stamp BETWEEN '2005-2-20 00:00:00.00000' AND '2005-2-20 23:00:00.000000'";
                ResultSet resultSet = statement.executeQuery( sqlQuery );
                out.println( "<TITLE> Servlet DB Test by Mitch </TITLE>" );
                out.println( "</HEAD>" );
                out.println( "<BODY>" );
                out.println( "<P>This is a test to connect to a database, execute a simple SELECT and display the results below." );
                out.println( "<br>\n<br>" );
                Integer intObject;
                while ( resultSet.next() )
                   intObject = new Integer( resultSet.getInt( 1 ) );   
                   Array.add( intObject );
                resultSet.close();
                for( int i = 0; i < Array.size(); i++)
                 out.println(Array.get(i));
                out.close();
            }//end try
            catch ( SQLException sqlEx )
                sqlEx.printStackTrace();
                out.println( "<TITLE>ERROR</TITLE>" );
                out.println( "<HEAD>" );
                out.println( "<BODY><P>An error occurred.<br>Contact Mitch!" );
                out.println( "</P></BODY></HTML>" );
                out.close();
            catch( Exception exception )
               exception.printStackTrace();
               throw new UnavailableException( exception.getMessage() );
        //else
        //    out.println( "<h1>This indicates an old session</h1>" );
        }//doPost end
        public void destroy()
            try
                statement.close();
                connection.close();
            catch( SQLException sqlEx )
                sqlEx.printStackTrace();
        }//end destroy
    }//end Class
           

  • JDBC / Servlet / ": Io exception: SO Exception was generated"

    Hi,
    i am trying to write a simple Servlet program that would access oracle 9i database and display the names in the "emp" table in the form of a html page.
    I am using tomcat 4.0, jdk1.2.2, oracle 9i, windows 98.
    I am getting this exception as the outoput of the program:
    "Io exception: SO Exception was generated "
    The input of the program will be through a html file, with a form that will ask the user for his/her name(this has got nothing to do with the logic of the program.. just for the sake of using a html form):
    HTML file:
    <html>
    <head>
    <title>First Aplet</title>
    </head>
    <body>
    <FORM METHOD=GET ACTION="http://localhost:8080/Hello">
    What is your name?
    <input type=text name="name"><p>
    <input type=submit>
    </form>
    </body>
    </html>
    The code for the servlet class is as follows:
    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Hello extends HttpServlet{
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws
         ServletException, IOException{
              res.setContentType("text/html");
              PrintWriter out = res.getWriter();
              String name = req.getParameter("name");
              Connection con = null;
              Statement stmt = null;
              ResultSet rs = null;
              String name = req.getParameter("name");
              res.setContentType("text/html");
         out = res.getWriter();
         try{
         DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
         con = DriverManager.getConnection(
              "jdbc:oracle:thin:@","scott","tiger");
                   stmt = con.createStatement();
         rs = stmt.executeQuery("SELECT * from EMP");
    out.println("<HTML><HEAD><TITLE>EMp Table Details for "+name+"</TITLE></HEAD>");
         out.println("<BODY>");
              out.println("");
                   out.print("<TABLE>\n");
              try{
                   ResultSetMetaData rsmd = rs.getMetaData();
                   int numcols = rsmd.getColumnCount();
                   out.print("<TR>");
                   for(int i = 1;i<=numcols;i++)
                        out.print("<TH>"+rsmd.getColumnLabel(i));
                        out.print("</TR>\n");
                        while(rs.next()){
                        out.print("<TR");
                        for(int i=1;i<=numcols;i++){
                        out.print("<TD>");
                        Object obj = rs.getObject(i);
                        if(obj!=null)
                             out.print(obj.toString());
                        else
                             out.print(" ");
                   out.print("</TR>\n");
                   catch(SQLException e){
                   out.print("SQLEXception : "+e.getMessage());
              out.println("</TABLE>");
              out.println("</BODY></HTML>");
              catch(SQLException e){
                   out.println("SQLEXception caught: " + e.getMessage());
         public String getServletInfo(){
                             return "A servlet that knows the name of the person to whom it is saying hello";
    can anyone help?
    thanks..
    KdevRaya

    The getMetaVersion is not the problem, it works ok.
    the problem is the second connection
    conn = DriverManager.getConnection ("jdbc:oracle:thin:@database",info);
    This is exactly as it is illustrated in the "JDBC Developer?s Guide and R
    Reference" from oracle for release 9.2 Part No. A96654-01 page 3-8
    //import packages and register the driver
    import java.sql.*;
    import java.math.*;
    DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
    //specify the properties object
    java.util.Properties info = new java.util.Properties();
    info.put ("user", "sys");
    info.put ("password", "change_on_install");
    info.put ("internal_logon","sysdba");
    //specify the connection object
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@database",info);"

  • Proxies to jdbc scenario help...!

    Dear All,
    I am very new to XI , can anyone guide me step by step process for
    1. File to webservice scenario via xi
    2. Proxies to jdbc  scenario via xi
    3.IDOC to JDBC scenario via xi
    will be much helpful as i need to complete these processes very soon.
    Thanks in Advance.

    HI,
    Here are the documents:
    Webservice scenario:
    these 3 documents should explain it all,
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/befdeb90-0201-0010-059b-f222711d10c0
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5f3ee9d7-0901-0010-1096-f5b548ac1555
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/d23cbe11-0d01-0010-5287-873a22024f79
    troubleshooting SOAP:
    /people/varadharajan.krishnasamy/blog/2007/01/09/troubleshooting-soap-message--xi
    IDOC and JDBC Scenarios:
    /people/prateek.shah/blog/2005/06/08/introduction-to-idoc-xi-file-scenario-and-complete-walk-through-for-starters --> For Idoc sender: IDOC -file
    /people/sap.user72/blog/2005/06/01/file-to-jdbc-adapter-using-sap-xi-30 --> for jdbc receiver: file -JDBC
    IDOC configuration :
    Refer the help:
    /people/swaroopa.vishwanath/blog/2007/01/22/ale-configuration-for-pushing-idocs-from-sap-to-xi - ALE settings for R3-XI
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e07dcaa0-a92b-2a10-3a96-b3d942bd1539
    Idoc to File:
    /people/prateek.shah/blog/2005/06/08/introduction-to-idoc-xi-file-scenario-and-complete-walk-through-for-starters
    This is expalined both the scenarios:
    Please follow the below process for configuration:
    Pre-requisites for Inbound IDoc to R/3 from PI:
    Configuration required at Xi side:
    Go to IDX1: configure the port.
    Go to IDX2: load the DOC metadata.
    Go to SM59: Create RFC destination which points to R3 system this is require in the case where your IDOC is sent to R 3 system,
    Configiration required at R3 side:
    Maintain Logical System for PI (SALE transaction):
    Maintain Partner Profile for XI system(WE20):
    Pre-requisites for Outbound IDoc from R/3 to PI:
    Configurations required in R/3:
    Maintain Logical System (SALE)
    Define RFC Destination (SM59) which points to PI system
    Maintain Port (WE21)
    Maintain partner profile. (WE20):
    Maintain Distribution Model (BD64):
    JDBC:
    Receiver JDBC scenario MS access - /people/sameer.shadab/blog/2005/10/24/connecting-to-ms-access-using-receiver-jdbc-adapter-without-dsn
    Writing Stored Procedures-
    /people/siva.maranani/blog/2005/05/21/jdbc-stored-procedures
    http://www.ics.com/support/docs/dx/1.5/tut6.html
    /people/sriram.vasudevan3/blog/2005/02/14/calling-stored-procs-in-maxdb-using-sap-xi
    http://www.ics.com/support/docs/dx/1.5/tut6.html
    http://java.sun.com/docs/books/tutorial/jdbc/basics/sql.html
    http://www.sqlteam.com/article/stored-procedures-an-overview
    Proxy:
    Client Proxy:
    /people/ravikumar.allampallam/blog/2005/03/14/abap-proxies-in-xiclient-proxy
    Server Proxy:
    /people/siva.maranani/blog/2005/04/03/abap-server-proxies
    Smarter Approach for coding ABAP Proxies
    /people/sravya.talanki2/blog/2006/07/28/smarter-approach-for-coding-abap-proxies
    File to Inbound Proxy:
    /people/prateek.shah/blog/2005/06/14/file-to-r3-via-abap-proxy
    How do you activate ABAP Proxies?
    /people/vijaya.kumari2/blog/2006/01/26/how-do-you-activate-abap-proxies
    Debugging Inbound Proxy:
    /people/stefan.grube/blog/2006/07/28/xi-debug-your-inbound-abap-proxy-implementation
    Thanks and Regards,
    Chirag Gohil

  • ClassNotFoundException in running jdbc servlet

    hi
    i've wrote a servlet to connect to my Teradata db but when i run it
    on tomcat i get this java lang exeption:
    ClassNotFoundException: com.ncr.teradata.TeraDriver
    the thing is that the connection and sql code work on an application withoput any problems, but when i try to use on a servlet i get this exception...
    why??
    maybe i have to change some settings of tomcat.. ?
    hope someone can say smth about
    thanks!

    You need to tell Tomcat where to find the JDBC driver, remember that the Tomcat Classpath overrides the JDK classpath. For example, in Tomcat 3.x you need to put the driver in tomcat-installation/lib/common
    Just be sure that the JDBC is a jar file, Tomcat cannot read zip files.
    Hope this help.

  • JDBC/Servlets Connectivity Problems.

    Hi,
    I'm new to Java development.
    I'm trying to run this simple Servlet on
    OS : Sun Solaris 2.6
    Web Server : Netscape Enterprise Server
    Database : Oracle 8i
    JDK2 and JSDK2 installed on the Server.
    JDBC Driver : Native Oracle JDBC Driver
    This program works perfect on the Server if I run it as a program (Not a Servlet). However when running it as a Servlet, JUST DOESN't do ANYTHING. Doesn't return any error nor does execute the SQL Command.
    Also how can I enable tracing to Trap errors generated on the Server by the Servlet.
    Thanks for all your help....
    Here's the Pogram:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import java.sql.*;
    import oracle.jdbc.driver.*;
    public class CreateTable1 extends HttpServlet {
    public void init(ServletConfig config)
    throws ServletException {
    super.init(config);
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    doGet(request, response);
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html");
    ServletOutputStream out = response.getOutputStream();
    out.println("<html>");
    out.println("<head><title>CR2Reat Table Server</title></head>");
    out.println("<body>");
    out.println("<br>Before Create...");
    try {
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    Connection con = DriverManager.getConnection("jdbc:oracle:kprb:@oracle","uername","password");
    Statement statement = con.createStatement();
    statement.executeUpdate("CREATE TABLE kj_newCont1" +
    "(title_id NUMBER, title_name VARCHAR2(50)," +
    "rating CHAR(5), price NUMBER(7,2), quantity NUMBER," +
    "type_id INTEGER, category_id INTEGER)");
    catch (SQLException sqle) {
    System.err.println(sqle.getMessage());
    catch (Exception e) {
    System.err.println(e.getMessage());
    out.println("<br>AfterClose");
    out.println("</body></html>");
    out.close();
    public String getServletInfo() {
    return "Title Servlet return Information...";
    null

    To run servlets you must have a special server to run them like JRun or Java Web Server visit www.allaire.com to download JRun
    You must also download the servlet.jar
    java.sun.com
    you must configure your CLASSPATH too
    CLASSPATH=".:<path>classes12_01.zip":".:<path>servelet.jar"
    I'm using Red Hat Linux 6.2 I think this can Help you

  • Exception in AdminRealm servlet, help needed

    I am trying to install the WebLogic LDAP realm, but I get an exception
    when I try to test the LDAP realm using the AdminRealm servlet.
    Through wlpsadmin, I managed viewing groups and search users, but the
    LDAP tab displays no values and I could not login to my portal with
    users defined in the LDAP server.
    I attached the HTML file returned by the server after calling
    AdminRealm.
    Any Ideas ?
    10x, Eli Kaplan.
    [att1.html]

    Hi Eli
    In the portal definition in your weblogic.properties file, there is a
    property called groupname, set this to the name of your LDAP group, this
    should solve the problem.
    May
    "Eli Kaplan" <[email protected]> wrote in message
    news:[email protected]
    Hi,
    I solved the exception by deleteing the users and groups from the LDAP
    server and defining them again.
    Another question : I want to allow login to my portal only to certain
    groups of users that are defined in my LDAP server, however - all the
    users, regardless of their groups, are able to login currently...
    What should I do to allow login only to some groups, and not to others ?
    Thanks again, Eli.
    Eli Kaplan wrote:
    I am trying to install the WebLogic LDAP realm, but I get an exception
    when I try to test the LDAP realm using the AdminRealm servlet.
    Through wlpsadmin, I managed viewing groups and search users, but the
    LDAP tab displays no values and I could not login to my portal with
    users defined in the LDAP server.
    I attached the HTML file returned by the server after calling
    AdminRealm.
    Any Ideas ?
    10x, Eli Kaplan.
    An Exception occurred:
    java.lang.NullPointerException:
    at
    weblogic.security.ldaprealm.LDAPDelegate.magicBunny(LDAPDelegate.java:292)
    atweblogic.security.ldaprealm.LDAPDelegate.addGroupMember(LDAPDelegate.java:61
    1)
    atweblogic.security.ldaprealm.LDAPDelegate.getGroupMembers(LDAPDelegate.java:5
    75)
    atweblogic.security.ldaprealm.LDAPDelegate.getGroupMembers(LDAPDelegate.java:5
    18)
    atweblogic.security.ldaprealm.LDAPRealm.getGroupMembersInternal(LDAPRealm.java
    :81)
    atweblogic.security.acl.AbstractListableRealm.getGroupMembers(AbstractListable
    Realm.java:302)
    atweblogic.security.acl.FlatGroup.ensureFreshness(FlatGroup.java:149)
    at weblogic.security.acl.FlatGroup.members(FlatGroup.java:236)
    at admin.AdminRealm.composePage(AdminRealm.java:176)
    at admin.AdminServlet.service(AdminServlet.java:257)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
    atweblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
    :105)
    atweblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
    l.java:742)
    atweblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
    l.java:686)
    atweblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContext
    Manager.java:247)
    atweblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:363)
    atweblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:263)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    [Home][Event topics][Event registrations][JDBC info][Licenses]
    [Properties][Workspaces][Connections][Threads][Versions][Realm][Help]
    [Image]
    [Image]
    [WebLogic home]
    WebLogic Realm for [email protected]
    [Image]
    [Home][Event topics][Event registrations][JDBC info][Licenses]
    [Properties][Workspaces][Connections][Threads][Versions][Realm][Help]

  • Regd JDBC SERVLET

    hi friends,
    Question 1:It's regarding JDBC using PreparedStatement from Servlets. I created a table named st in ORACLE having columns name varchar2(20) and dateofbirth date. From insert.htm, i am accepting, the data for dateofbirth as a string; i.e., <Input type="TEXT"...>.
    Now my question is how to convert this dateofbirth of string into SQL ORACLE data type and then store in DB.
    Processing is taking place in Servlet; i.e., from htm to servlet to ORACLE Db.
    Question 2: How can i store boolean values from servlet into Oracle DB & how to retrieve back.
    Plz help me in this regard....
    thank u...

    You can use java.text.SimpleDateFormat to convert String to Date.
    This problem has nothing to do with Servlets, JDBC, let alone Oracle.

  • Retrieving cell values from html in servlet - help!

    Dear all,
    I've got a table. I want to put links in each cell box. No problem. However I want to know when i've moved to my link what number cell the link came from. This is proving to be a big problem.
    Here is what i've tried:
    writer.println("<TR><TH bgcolor=\"brown\">Brown<TD id=1><li>
    <a href=BookingFromScreen>1</a></li></TD>" +
    "<TD name = \"id\" value = \"2\"><li><a href=BookingFromScreen>2</a></li></TD>".. etc...
    then picking the id's up in BookingFromScreen like this:
    String cell = request.getParameter("id");
    String cellNo= request.getParameter("value");
    System.out.println("this is the cell parameter: " +cell);
    System.out.println("this is the cell Number: " +cellNo);
    Object cell1 = request.getAttribute("id");
    String cell2 = (String)cell1;
    System.out.println("this may work: "+cell2);
    neither of these ways work, once link has been clicked all the information about that cell is lost, can anyone pleeeeeeeeeease tell me why this isn't working? both are in the doGet methods of their respective servlets if thats any help....
    thank you
    Jen C

    just use
    writer.println("<TR><TH bgcolor=\"brown\">Brown<TD id=1><li>
    <a href=BookingFromScreen?id=1>1</a></li></TD>" +
    "<TD name = \"id\" value = \"2\"><li><a href=BookingFromScreen?id=2>2</a></li></TD>"also you should be using a jsp for this

  • Trying to create object of a class within servlet - help!!

    I have created and compiled the following classes within
    C:\bea\wlserver6.1\config\mydomain\applications\DefaultWebApp\WEB-INF\classes
    1)LoginServlet
    2)LoginManager
    3)I have LoginServlet trying to create an object of type LoginManager, very simple,
    but I get the following errors:
    Cannot resolve symbol: LoginManager lm = new LoginManager();
    ^
    Cannot resolve symbol: LoginManager lm = new LoginManager();
    ^
    4)I have the .java and .class files located within the same directory, so I don't
    see what's wrong here??? HELP!
    LoginManager looks like:
    public class LoginManager {
    public boolean authenticateUser(String username, String password){
              boolean status = false;
    //simple code for string matching
              return status;
    LoginServlet looks like:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class LoginServlet extends HttpServlet {
         // Constructors
         // Variables
         public static final String CONTENT_TYPE = "text/html";
         public boolean LOGIN_STATUS;
         // Methods
         public void service (HttpServletRequest req, HttpServletResponse res)
              throws IOException {
              String username = "";
              String password = "";
              LoginManager lm = new LoginManager();
              username = req.getParameter("username");
              password = req.getParameter("password");
              LOGIN_STATUS = lm.authenticateUser(username, password);
              res.setContentType(CONTENT_TYPE);
              PrintWriter out = res.getWriter();
              out.println("<html><head><title>Hello World</title></head>" +
                             "<body>Hello! Your login status is " + LOGIN_STATUS +
                             "</body>" +
                             "</html>");
         public void init (ServletConfig config) throws ServletException {
              super.init(config);

    Do you have . in the CLASSPATH when compiling your servlet?
    ron <[email protected]> wrote:
    I have created and compiled the following classes within
    C:\bea\wlserver6.1\config\mydomain\applications\DefaultWebApp\WEB-INF\classes
    1)LoginServlet
    2)LoginManager
    3)I have LoginServlet trying to create an object of type LoginManager, very simple,
    but I get the following errors:
    Cannot resolve symbol: LoginManager lm = new LoginManager();
    ^
    Cannot resolve symbol: LoginManager lm = new LoginManager();
    ^
    4)I have the .java and .class files located within the same directory, so I don't
    see what's wrong here??? HELP!
    LoginManager looks like:
    public class LoginManager {
    public boolean authenticateUser(String username, String password){
              boolean status = false;
    //simple code for string matching
              return status;
    LoginServlet looks like:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class LoginServlet extends HttpServlet {
         // Constructors
         // Variables
         public static final String CONTENT_TYPE = "text/html";
         public boolean LOGIN_STATUS;
         // Methods
         public void service (HttpServletRequest req, HttpServletResponse res)
              throws IOException {
              String username = "";
              String password = "";
              LoginManager lm = new LoginManager();
              username = req.getParameter("username");
              password = req.getParameter("password");
              LOGIN_STATUS = lm.authenticateUser(username, password);
              res.setContentType(CONTENT_TYPE);
              PrintWriter out = res.getWriter();
              out.println("<html><head><title>Hello World</title></head>" +
                             "<body>Hello! Your login status is " + LOGIN_STATUS +
                             "</body>" +
                             "</html>");
         public void init (ServletConfig config) throws ServletException {
              super.init(config);
    Dimitri

  • Sending a file from Applet to servlet HELP me Please

    Sorry, i have the problem this is my code Applet & Servlet but it seems working asynchronously if you have some ideas please reply me i send bytes on outputstream but the inputstream of servlet receive nothing bytes but write my system.out.print on screen server:
    Applet:
    URL servletURL = new URL(codebase, "/InviaFile/servlet/Ricevi");
    HttpURLConnection urlConnection = (HttpURLConnection) servletURL.openConnection();
    urlConnection.setRequestMethod("POST");
    urlConnection.setUseCaches(false);
    urlConnection.setDoOutput(true);
    urlConnection.setDoInput(true);
    urlConnection.setAllowUserInteraction(false);
    urlConnection.setRequestProperty("Content-Type", "application/octet-stream");
    urlConnection.setRequestProperty("Content-length", String.valueOf(100));
    urlConnection.connect();
    if(urlConnection.HTTP_BAD_REQUEST == HttpURLConnection.HTTP_BAD_REQUEST){
    /*System.out.println("Cattiva Richiesta: "+urlConnection.getContentEncoding());
    System.out.println("Tipo di metodo: "+urlConnection.getRequestMethod());
    System.out.println("Tipo di Risposta: "+urlConnection.getResponseCode());
    System.out.println("Tipo di messaggio: "+urlConnection.getResponseMessage());
    System.out.println("Tipo di contenuto: "+urlConnection.getContentType());
    System.out.println("Tipo di lunghezza contenuto: "+urlConnection.getContentLength());
    System.out.println("Tipo di doinput: "+urlConnection.getDoInput());
    System.out.println("Tipo di doouput: "+urlConnection.getDoOutput());
    System.out.println("Tipo di URL: "+urlConnection.getURL());
    System.out.println("Tipo di propriet� richiesta: "+urlConnection.getRequestProperty("Content-Type"));
    System.out.println("Entra if");
    DataOutputStream dout = new DataOutputStream(urlConnection.getOutputStream());
    InputStream is = urlConnection.getInputStream();
    if(ritornaFile("C:/Ms.tif", dout))System.out.println("Finita lettura");
    dout.close();
    urlConnection.disconnect();
    System.out.println("Fine Applet");
    }catch(Exception e) { System.err.println(e.getMessage());e.printStackTrace();}
    public boolean ritornaFile(String file, OutputStream ots)throws Exception{
    FileInputStream f = null;
    try{
    f = new FileInputStream(file);
    byte[] buf = new byte[4 * 1024];
    int byteLetti;
    while((byteLetti = f.read()) != -1){ots.writeByte(buf, 0, byteLetti);ots.flush();
    while((byteLetti = f.read()) != -1){ots.write(byteLetti);ots.flush();
    System.out.println("byteLetti= "+byteLetti);
    return true;
    }catch(Exception ex){
    System.err.println(ex.getMessage());
    return false;
    }finally{
    if(f != null)f.close();
    Servlet:
    HttpSession ses = request.getSession(true);
    System.out.println("Passa servlet "+request.getMethod());
    System.out.println("Passa servlet "+ses.getId());
    ServletInputStream servletinputstream = request.getInputStream();
    DataInputStream dis = new DataInputStream(request.getInputStream());
    int c = dis.available();
    System.out.println("c="+c);
    //ServletOutputStream servletoutputstream
    //response.getOutputStream();
    response.setContentType("application/octet-stream");
    System.out.println("URI= "+request.getRequestURI());
    System.out.println("pathTranslated: "+request.getPathTranslated());
    System.out.println("RemoteUser: "+request.getRemoteUser());
    System.out.println("UserInRole: "+String.valueOf(request.isUserInRole("")));
    System.out.println("pathInfo: "+request.getPathInfo());
    System.out.println("Protocollo: "+request.getProtocol());
    System.out.println("RemoteAddr:"+request.getRemoteAddr());
    System.out.println("RemoteHost:"+request.getRemoteHost());
    System.out.println("SessionID:"+request.getRequestedSessionId());
    System.out.println("Schema:"+request.getScheme());
    System.out.println("SeesionValido:"+String.valueOf(request.isRequestedSessionIdValid()));
    System.out.println("FromURL:"+String.valueOf(request.isRequestedSessionIdFromURL()));
    int i = request.getContentLength();
    System.out.println("i: "+i);
    ritornaFile(servletinputstream, "C:"+File.separator+"Pluto.tif");
    System.out.println("GetMimeType= "+getServletContext().getMimeType("Ms.tif"));
    InputStream is = request.getInputStream();
    int in = is.available();
    System.out.println("Legge dallo stream in="+in);
    DataInputStream diss = new DataInputStream(servletinputstream);
    int ins = diss.read();
    System.out.println("Legge dallo stream ins="+ins);
    int disins = diss.available();
    System.out.println("Legge dallo stream disins="+disins);
    is.close();
    System.out.println("Fine Servlet");
    catch(Exception exception) {
    System.out.println("IOException occured in the Server: " + exception.getMessage());exception.printStackTrace();
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    processRequest(request, response);
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    processRequest(request, response);
    /** Returns a short description of the servlet.
    public String getServletInfo() {
    return "Short description";
    public void ritornaFile(InputStream its, String fileDest )throws Exception{
    FileOutputStream f = null;
    try{
    f = new FileOutputStream(fileDest);
    byte[] buf = new byte[2 * 1024];
    int byteLetti;
    while((byteLetti = its.read()) != -1){
    f.write(buf, 0, byteLetti);
    f.flush();
    System.out.println("Byteletti="+byteLetti);
    }catch(Exception ex){
    System.err.println(ex.getMessage());
    }finally{
    if(f != null)f.close();

    Hi all,
    Can anyone help me.I am trying to send an audio file from a applet to servlet with HTTP method(no raw sockets), also the servlet shld be able to save the file on the server.Any suggestions welcome.USing audiostream class from javax.sound.sampled.
    The part of applet code which calls servlet is :
    URL url = new URL("http://" + host + "/" + context + "/servlet/UserUpdateWorkLogAudio?userid=" + userId.replace(' ', '+') + "&FileName=" + filename.replace(' ', '+'));
    URLConnection myConnection = url.openConnection();
    myConnection.setUseCaches(false);
    myConnection.setDoOutput(true);
    urlConnection.setRequestProperty("Content-Type", "application/octet-stream");
    myConnection.connect();
    out = new BufferedOutputStream(myConnection.getOutputStream());
    AudioSystem.write(audioInputStream, fileType,out); // IS THIS RIGHT APPROACH?
    ************************end of applet code**********************
    ************************servlet code******************************
    try
    {BufferedInputStream in = new BufferedInputStream(request.getInputStream());
    ????????What code shld i write here to get the audio file stream
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(filename));
    *********************************************end***********************
    Thanks
    Joe.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to use % wildcard in jdbc plz help me

    Hello all,
    try
         PreparedStatement st=dbcon.prepareStatement("select * from stud2  where ename=? ");
    st.setString(1,ename+"%");
    ResultSet rs=st.executeQuery();
    while(rs.next())
    out.println("<td>");
    out.println(rs.getString(2));//this field is for name
    out.println(rs.getString(3));//this is for addresss
    }catch(Exception e){}This code is in servlets,and iam using MS-ACCESS as database.
    in this way iam trying this code , usage of %wild card but iam not getting the right anser, i want the anser if i will type any letter it should search the database and display me all names of that letter
    plz help me solving this problem
    vidya.

    PreparedStatement ps = con.prepareStatement("select blah from blah where blah like ?");
    ps.setString(1, "a%"); // everything that starts with 'a'
    rs = ps.executeQuery();

  • JDBC connector help

    Ok here we go,
    I want to work with MySQL and JSP from Dreamweaver . I installed TOMCAT 5.0 and everything is working fine. But... I can't connect to my MySQL. I have downloaded the connector from MySQL, Install it and here is my
    CLASSPATH : C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\jsp-api.jar;C:\Program Files\MySQL\MySQL Server 4.1\mysql-connector-java-3.1.5-bin.jar;
    When I try to connect I get the no suitable driver message. Can anybody help!!
    Thanks.
    Kriegerman

    It would help others to help you if you were to post the relevant code and specify the line of code that is generating the exception. This is because the message "No suitable driver" does not necessarily mean that the driver class could not be loaded. Indeed it may be that your URL is incorrect.

Maybe you are looking for

  • Can't play the video in my Lumia 520

    Hi I always love the work of nokia and this time trailer app is just Nice but there's a problem. I have downloaded 6 trailers and only 1 is able to play. Rest of them says "sorry we can't play this video on your phone". I have no idea what's wrong wi

  • When do I really get a refund??? I has been 4 months and no one is willing to give me an answer!

    I closed my account with Verizon Fios on July 2014, when I was asked to pay a full balance when we knew it would end with a credit balance of $76.08. Since then I have called multiple times, and each time the associate I spoke to told me that he/she

  • Small thin white line

    I've got an issue I just noticed in the top left corner of my screen. There's a thin white line that doesn't extend the entire screen right by the apple menu. Screenshot: http://www.equals5.com/downloads/imac-screenshot.png It stays there even when I

  • This is in regards to the os x Maverick update.

    when i tried to log in the keychain box appeared and asked for my login password. from my memory i have never set up the keychain. how do i remove this box if the cancel button is not allowing me to do so?

  • "Z_COPCA_ACC_ASSIGNMENT_DEFAULT" Problem

    Hello everyone, I wanted the system to put the proposal default profit center for posting in FI. After maintaining the transaction 3KEH, the system did not consider the default profit center as a default value, so I found a note 124363 . I performed