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.

Similar Messages

  • 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!!!!!!!!

  • JDBC + SERVLET: inserting text data  to access file from Html form

    Hi everybody !
    I'm trying to insert text data from my html form to access database using servlet and jdbc technologies.
    The problem that I'm that the data is TEXT, but not the English language !!!
    So my access db file gets - ???????? symbols instead the real text.
    This is the form line that sending data to my servlet:
    <form
    method="POST"
    ACTION=http://localhost:8080/servlet/myServlet enctype="text/html">
    And this is servlet line that defines response content:
    res.setContentType( "text/html" );
    What can I do to get in access db file the right text format and not a ???????? symbols.
    Maybe I must to ad some <meta ...> , but where ?

    You're dealing with Unicode, I'd guess, and not ASCII.
    I guess I'd have two questions:
    (1) Is the character encoding on your pages set properly for the language you're trying to use?
    (2) Does Access handle Unicode characters?
    Access isn't exacly a world-class database. (If it was, there'd be no reason for M$ to develop SQL Server.) I'd find out if it supports other character sets. If not, you'll have to switch to a more capable database that does. - MOD

  • 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);"

  • 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

  • Oracle/JDBC servlet problem

    My code and error message are found below:
    Why can't I resolve the variable "val"?
    Thanks
    package moreservlets;
    import java.sql.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    /** Simple servlet used to test the use of packages. */
    public class TitleQueries extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = "Connecting to Database";
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@pc840:1521:orcl", "scott", "tiger");
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery
    ("select * from emp");
    while (rset.next()) {
    String val = rset.getString(1);
    catch(ClassNotFoundException cnfe) {
    System.err.println("Error loading driver: " + cnfe);
    catch(SQLException sqle) {
    System.err.println("Error connecting: " + sqle);
    out.println(ServletUtilities.headWithTitle(title) +
    "<body bgcolor=\"#FDF5E6\">\n" +
    "<h1 align=\"center\">" + title + "</h1>\n" +
    "<h1 align=\"center\">" + val + "</h1>\n" +
    "</body></html>");
    C:\J2ee\moreservlets>javac -d "C:\Program Files\Apache Tomcat 4.0\webapps\ROOT\W
    EB-INF\classes" TitleQueries.java
    TitleQueries.java:46: cannot resolve symbol
    symbol : variable val
    location: class moreservlets.TitleQueries
    "<h1 align=\"center\">" + val + "</h1>\n" +
    ^
    1 error

    You're declaring the variable "val" inside your while loop, which gives the variable scope inside that loop. As soon as the loop finishes executing, that variable will cease to be.
    Instead, declare the variable outside the while loop, and you can access it later on without any problems...
    String val = null;
    while (rset.next()) {
    val = rset.getString(1);
    }Just fyi though, in the current setup, you're only going to end up with the very last value retrieved from teh database, since you're overwriting val each time you loop through the resultset. If you want to keep all the variables, maybe use an ArrayList?

  • JDBC & Servlets

    I am writing some servlets that write to a sQL Servler database, reading from a html form.
    I have noticed that when I enter a name to a html text field, it will not take any characters after a blank space, and similiarily after a new line in a html textarea.
    this is how i get the info from the form:
    String name = request.getParameter("name");
    I am then inserting the data via sql query :
    Insert into EmployeeDetails values ('"+uid+"', '"+name+"') ");
    etc...
    Any help would be appreciated people
    Cheers

    sorry everyone, it is actually saving to the database but if i wanted to display the data in another text field, it will only display the first word.
    eg, I enter in joe bloggs and i see only joe in my new text field

  • Servlet-jdbc problem

    hello all,
    I am writing a simple servlet which will extract data (empno and empname) from a html form and insert in to database.
    everything seems to work fine except it inserts in to the table empno and empname as it is without values.
    if u can think of some reason and specify it would be great.
    thanx once again.
    mahesh
    anyway i have those 2 small programs as below :
    enterinfo.java - for generating entry form
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class EnterInfo extends HttpServlet
         public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
              res.setContentType("text/html");
              PrintWriter out=res.getWriter();
              out.println("<html><body>");
              out.println("<form name=\"insertdata\" method=\"post\" action=\"msgservlet\">");
              out.println("Emp No<input type=text name=empno><br>");
              out.println("Emp Name<input type=text name=empname><br>");
              out.println("<input type=submit value=send>");
              out.println("</form></body></html>");
    msgservlet.java - for extracting data and inserting data in to the table
    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class msgservlet 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");
              catch(ClassNotFoundException cnfe)     
                   System.err.println("Details:"+cnfe);
                   System.exit(0);
              try
                   conrjc();
                   //con=DriverManager.getConnection("jdbc:odbc:njdbc");
              catch(SQLException sqle){
              System.err.println("Details"+sqle);
         public void conrjc() throws SQLException
              con=DriverManager.getConnection("jdbc:odbc:njdbc");
         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</title>");
                   out.println("</head>");
                   out.println("<body>");
                   stmt=con.createStatement();
                   int eno=Integer.parseInt(req.getParameter("empno"));
                   String enm=req.getParameter("empname");
                   //String ins="insert into MYEMPLOYEE values('req.getParameter("empno")','req.getParameter("empname")')";
                   stmt.executeUpdate("insert into MYEMPLOYEE values(eno,enm)");
                   out.println("<h1>OK</h1>");
    //               stmt.close();
                   con.commit();
              catch(SQLException se){
              out.println("An SQL Exception was Thrown"+ se);
              catch(IOException se){
              out.println("An IO Exception was Thrown");
              out.println("</body>");
    out.println("</html>");
              out.close();          
              public void destroy(){
              try{
                   con.close();
              catch(SQLException sqle){}

    try using the following statement instead on the previous one...
    stmt.executeUpdate("insert into MYEMPLOYEE values('"+eno+"','"+enm+"')");
    Usually strings are passed as 'string' to be inserted into the database. Make sure you know what data type you are inserting into the database (from database design). However, prepared statement should work as well.
    Hope this helps
    AAJ

  • Using Oracle driver in JDBC for Unix and Linux based servers

    Please, let me know how to mention the Oracle driver within the forName.class(" "); statement in the Jdbc-Servlet for Unix and Linux based servers.
    I'm using Windows-OS for Java programming. Should I have to use the same environment(Unix/Linux with Oracle) for compiling or just compiling, mentioning the driver in the java program would suffice?
    Please, Help me.
    Thank You.
    from,
    Silas eschole.
    email: [email protected]
    [email protected]

    I've used Oracle's thin driver like this:
    Class.forName ( "oracle.jdbc.driver.OracleDriver" );
    Connection DBConnection = DriverManager.getConnection("jdbc:oracle:thin:USER/PASSWD@database" );
    You need Oracles client classes ( e.g. classes111.zip ) at run time, not during compilation.
    Thin client connects directly to the Oracle DB, so the database description is like PORT:MACHINE:SID
    Connection is made through Oracle's listener even when your DB is in the same machine that your program is running. Port number is propably 1521 or 1526, depending on your listener.ora definitions and used Oracle SQL*Net version.

  • How to use Servlets with O8i on RH Linux 6.2 ???

    I'm using apache Jserv 1.1.2 to run my servlets all my JDBC programs work fine and other servlets too but only JDBC servlets give this message
    "SQLException caught Io exception: The network adapter could not
    established the connection"
    Can someone tell me How to configure JSERV to make connection ?

    Hi there,
    If I understand correctly you are running Jserv and Apache to connect to an Oracle 8i db on a remote machine. If you are getting the "network adapter" error make sure the listener is running on the remote machine (lsntrctl start -- lsntrctl status, or something like that from bash shell). Also make sure SQLNet is configured properly. Try connecting from a machine with SQL Plus. If this works and the listener is running you should be in business.
    Best
    Scott ([email protected])
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by CSL ():
    I'm using apache Jserv 1.1.2 to run my servlets, a remote database on O8i on linux. all my JDBC programs work fine and other servlets too(with no JDBC) but only JDBC servlets give this message
    "SQLException caught Io exception: The network adapter could not established the connection"
    Can someone tell me How to configure JSERV to make connection ?<HR></BLOCKQUOTE>
    null

  • Newbie ?: EJB vs servlets

    I'm just starting out teaching myself J2EE related technologies. I have extensive development experience in other environments. I've only dabbled in Java quite a few years ago.
    I have a general sense of the difference between EJB and servlets but couldn't find an official description/comparison in any of the FAQs that I've read. Could someone please compare and contrast the two technologies?
    Also, I'd welcome any tips/suggestions regarding my learning experience, including but not limited to:
    - suggested sequence of learning supporting/related technologies (e.g. Java, JSP, servlets, JavaBeans, EJB, JDBC, JavaServer Faces, CORBA, OOAD, UML etc.)
    - recommended/popular development tools/IDEs etc.
    - learning resources/books etc.
    I'm currently reading the free PDF version of "Core Servlets and JSP" by Marty Hall.
    Thanks,
    Gary White

    Few Diffs:-
    1. Servlets run in a web container and EJBs run in a EJB Container.
    2. Use of Servlets is thru HTTP protocol and EJBs by look-up(internally RMI-IIOP)
    3. Developers has to explicity code for dattabaase transaction and security. EJBs: Container will manage every thing.
    4. Mainly: Servlets are server side code that generate dydnamic web page content to display. But EJBs are reusable component run in container.
    The sequence is: Java, JavaBeans, JDBC, Servlets, JSP, JSF & EJB
    I recommened JCreator LE IDE as it is developed in VC++ which runs fast. But another powerfull IDE is the Eclipse.
    Books:
    Java. Thinking in Java, Sun Tutorial
    JSP & Servlets: the book you are following work fine
    EJB> Mastering EJB by Ed Romans

  • DB Servlet failed to initialize ?

    I'm trying to port a working (JDBC) servlet from NES/Jrun to Oracle/Apache. I believe I have added the appropriate initArgs in the properties file, yet I'm getting an exception in the call of :
    public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException...
    null

    pirj wrote:After `chmod a+x /var/lib/pacman/local` problem has gone.
    So, what was the permission on this directory before you did this? And also what are the permissions on file inside /.../local?
    I am guessing that your user umask is propagated to sudo. Then, pacman sets this "wrong" permission on the local DB. That's one reason why sudo and su have to be used with caution, it's always better to just log in as root via tty or ssh as root into localhost.
    pirj wrote:
    Problems so far:
    1. Something goes wrong with non 022 umask (027 specifically).
    2. Error handling and error messages are not exactly correct.
    3. Pacman misses common 'en' locale and has a specific 'en_GB' one instead (doesn't seem to affect anything, but anyway).
    Is it all my fault or should be reported?
    (3) is not a problem because en_US is a default language, so there is no need for a localization (at least this is my understanding). That's why some small projects have no localization data inn /sur/share at all.
    (2) why?
    (1) Probably an issue with sudo.

  • Port(s) Used by JDBC

    Can anyone tell me what port(s) JDBC servlets use? I've got some programmers wanting to user JDBC servlets between machines and they must traverse the Internet and our firewall to do so. As the netadmin who also administers the firewall I have to open the appropriate ports.
    Many thanks!

    Hi,
    First mysql runs as standard on 3306, tomcat runs usually on either 80 or 8080 depending on the settings in the tomcat/sconf/server.xml file. DB2 runs on 50000, ssl runs on 543?
    But surely, if you are using a servlet on machine A and logging on using machine B, then you are using the port that is specified to connect between the two machines, and the local machine then connects to its local database, so the firewall is irrelevant to this. If this is not the case, then shoot your developers and get some new ones who are sending unecessary traffic across the network which is obviously allowing any one to sniff the connection.
    Make them use linux too, as the security is better and easier than other systems and runs on a miniscule amount of processing power as do all decent servers, and allows unlimited connections rather than the expensive beta version software that MS sell for vast amounts of money which often limits you to max five connectiosn if it works at all!
    Final point, avoid XP like the plague, it's almost as bad as ME, thats Windows ME not me!
    Sorry, back to ports. Our firewall for a project lab uses deny all. Then we add allow from as the students ask for it. Do this to your developers, and make them give you a good reason for why they need to run servlets across the network.
    best,
    kev

Maybe you are looking for