Using JDBC with JSP

I have a standalone application using Swing. Im converting it to a web / JSP/Servlets application.
Can my JSP acess my database using the same classes it used to or should I configure in my Tomcat a data source and call my database using the jndi name ?
thx in advance,
Giselle

Agreed - JSPs are best for presentation.
I have a front controller servlet that delegates to POJOs to do database interactions and then forwards results to JSPs for display. No scriptlet code in my pages, no database interactions, just looping through collections and displaying the results. - MOD

Similar Messages

  • Problem when using JDBC with JSP

    Hi,
    I am trying to display results after a database query on a JSP page, and then provide the options delete or update one of these records or to add a new one.
    What I did was to pass the ResultSet object to the webpage, and then display the result. When the buttons are pressed, I pass this ResultSet to another jsp page where I provide the required functionality. This is then forwarded back to the previous JSP, where the new data is displayed.
    However, when the first page is re-displayed, it creates a new connection and i was wondering if there is a way to close the previous connection through the ResultSet?
    Also, I wanted to put the ResultSet in a bean, but I think it is causing an error in the web server, saying something like it is not Serializable. Is there any other way to pass the ResultSet around?
    Any suggestions on better ways to manage databases though web interfaces would be welcome, or if someone could point me to a good tutorial on this topic!
    cheers
    Ankur

    Bad idea to be passing ResultSets around. Those are database cursors, a scarce resource.
    You should load that data into a data structure, close the ResultSet immediately, and then pass the data structure around in session if you must.
    Better yet, have a central servlet that deals with all database calls. Let the JSPs just do display, as they were meant to. - MOD

  • Help me!! How to use JavaScript with JSP ??

    I am using JDeveloper and I created a screen in JSP which uses a bean for database connectivity and retriving info onto the page.
    The page has a ListBox where list items are populated from the database.My requirement is
    whenever the list is changed the page shuold be refreshed with the selected item info.
    I tried to use 'JavaScript' for triggering the event with 'onChange' event of the ListBox.But the event is not getting invoked. I think JavaScript is not working with JSP.
    Please help me with how to Use javaScript with JSP or any other alternative where I can meet my requirement.
    I have one more question...I have gone through the JSP samples in OTN and I am trying do download the sample 'Travel servlet' which show list of countries...etc
    I have also gone through the 'readme' but I don't know how to extract .jar file.
    I would be great if you could help me in this.
    Thanks!!
    Geeta
    null

    We have a similar need. We have used Cold Fusion to display data from Our Oracle Database. We have a simple SElect Box in HTML populated with the oracle data. When someone selects say the State of Pennsylvania. then we have an On change event that runs a Javascript to go get all the cities in Pennsylvania.
    Proble we are having is that inorder for the Javascript to work , we currently have to send all the valid data.
    Do you know of any way to dynamically query the the Oracle database in Javascript

  • How to use unload query using JDBC with Informix database

    Hi friends,
    How can i use unload query using JDBC with Informix database?
    When i use it as "unload to 'abc.txt' select * from ........" it gives syntax error.I want to take the data of a table to a file.With dbaccess i can use it but i need to do it using jdbc.
    Thanks,
    Raneesh.

    To the best of my ability to tell, the right way to use this product from within Power Query would be to use its API. Unfortunately, we don't currently support either of the methods needed to be able to authenticate with the service (OAuth 2.0 and a relatively-custom
    digest-based method). Adding a mechanism to allow use of arbitrary OAuth-protected resources is a fairly high priority for us, and I hope we'll be able to deliver something before mid-2015.
    Scraping the website is very hard to do well -- both from an authentication and from a data discovery perspective.

  • How use jdbc with swing ? i am new in this concept.

    hi
    freinds,
    i am new in java can any one give the example which explain the how to use jdbc with swing.
    thanks in advace.
    satish
    thanks.

    See here  >  http://support.apple.com/kb/HT4236
    More info in the User Guides for your Devices...

  • Using JDBC with Oracle

    I have just completed compiling and running a simple UI through a java command line interface, however part of my program is running into a problem. I have to connect to Oracle through JDBC, but the server I am not on does not have the oracle drivers. I have copied them over (in tar as distributed) but I have never had to extern any thing like this. I am running on a standard linux bash prompt and need to know what to do to actually change everything so my program can run the database connectivity.
    Simply put, is there a way to compile so the byte code never needs the .jar, and if not how about making my program see the jar which is in my root folder (not root on the server, but my user root folder)
    I hope that was enough info, if not I'll do my best to provide more.

    Hmm, maybe I'm not quite making sense.
    Let's say I want to run my program on my neighbor's machine (A) to connect to an Oracle database on my machine (B). My neighbor has Java version 1.4.2, and my machine has Java version 1.4.2 also. My oracle database is running Oracle 8i (8.1.6.0.0) my machine. Let us also assume that my neighbor, while desiring a program to connect to my database, wants everything to be included in a single directory and no global system settings to be permananty changed. He doesn't mind if I change setting for the current session if need be.
    Now, I make the Java program on my machine and it works just fine. Since I have Oracle installed on my machine the command "java dbConnect" has no problem running. Now I take the program over to my neighbor's computer with the following files in the current program directory (not the java installation directory):
    dbConnect
    ojdbc14.jar
    This I hope would allow me to run the program since I thought (in error) that the program would probably be able to find the ojdbc14.jar since it is in the directory of the dbConnect program. Unfortunately it runs correctly, then fails to load the oracle driver.
    So now here is my real question. I want to be able to have my neighbor run my application, so what do I do to run the application dbConnect.java on their computer?
    I have tried the following, however it gives an exception in the thread when I run this
    javac dbConnect.java
    java -classpath ./ojdbc14.jar dbConnect
    Exception in thread "main" java.lang.NoClassDefFoundError: dbConnect.The program right now is simply a test to see if I can load the driver and make a connection, and it works on my system, so there should be no problems:
    import java.io.*;
    import java.sql.*;
    public class dbConnect
        //Create an input stream for reading data from the user
        private static BufferedReader stdin =
            new BufferedReader(new InputStreamReader(System.in));
        public static void main(String[] args)
            try{
                //>Load the Oracle JDBC Drivers
                try
                    Class.forName("oracle.jdbc.driver.OracleDriver");
                catch(Exception e)
                    System.out.println("Failed to load Oracle driver.");
                    System.exit(0);
                //>Get username, password, and url for Oracle DB connection.
                String user, pass, url;
                System.out.println("Please enter your username: ");
                user = stdin.readLine();
                System.out.println("Please enter your password: ");
                pass = stdin.readLine();
                url = "jdbc:oracle:thin:@somewhere:1521:csl";
                Connection conn = null;
                Statement stmt = null;
                //>Successfully connect to the Oracle database using JDBC and CSLab account.
                try
                    conn = DriverManager.getConnection(url, user, pass);
                    System.out.println("Connection made!");
                catch(Exception e)
                    System.out.println("Incorrect login information.");
                    System.exit(0);
            }catch(Exception e){
                System.out.println("Exception in main program.  Terminating process.");
    }

  • Connecting to MSAcess database using JDBC in JSP

    Hi,
    I have created an Aceess database file (C:\db1.mdb) and created a DSN=db1.
    I could able to connect to the database and retrieve the information from the tables using Sun's JDBC OdBc bridge drivers.
    DriverManager.getConnection("jdbc:odbc:db1").
    It was working Fine in my Standalone java program.
    But,when I used the database connection statements in my JSP page,it is not displaying any error message and not selecting rows from the Select statement i used in my JSP page.(The same worked in my standalone Java program).
    I executed the two programs on same machine.Database is also on the same machine.
    Can anyone tell me what shall i do to connect to the database(C:\db1.mdb) through JSP.
    Thanks in Advance
    Rao...

    in your code do you have any things that is suppressing your exception?? i.e. something lik
    try
    // do your stuff
    catch(Exception e)
    // do nothing??
    }if so you vont get to know of any problem that happened....
    also if there is an un handled exception the jsp page will sometimes come up as blank, because your print streem will be terminated abrubtly....
    this will probably happen if you dont have a try - catch block at all, or if you are not handling the exception that is being thrown.... try inclosing your code in a try catch block and doing ex.priintStackTrace() in the catch block to get the exception trace on the server console....
    also can you post some code for both your java client and jsp??

  • Using JARs with JSP?

    How do you include JARs in a classpath so that the classes inside can be referred to in <%@ page import="mypackageinajar.myclassinajar" %> ? I've looked through the JSP docs but it only covered import statements. If I can't use a JAR, how would I enable my program to access the class files that I could just manually extract from the JAR?
    Thanks

    How do you include JARs in a classpath so that the
    classes inside can be referred to in <%@ page
    import="mypackageinajar.myclassinajar" %> ? I've
    looked through the JSP docs but it only covered
    import statements. If I can't use a JAR, how would I
    enable my program to access the class files that I
    could just manually extract from the JAR?You can use JARs, but this is simply a question of how to pack your stuff into a WAR. It has nothing really to do with JSPs...
    http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/WebComponents3.html

  • Why folks afraid to use jdbc with oracle

    I use:
    1) select * from russian_name;
    2) native2toascii
    3) javac
    4) java
    Java.langArrayIndexOutOfBoundException
    at oracle.jdbc.dbaccess.DBConversion.ut8BytesToChar
    In the case of non existent table name it throw:
    SqlException - table does not exist - just right
    In win, unix, linux - everything with different versions.
    But sometimes it return many recods looks like - "KG UYGUYBG (null) (null) iloirdoidfogidf oidro oireio ddfoidfoid foi9eri o9er (null) (null)"...

    Hi,
    I'm new to using JDBC. I have found some really good
    sources online that have good info on how to get
    started and all. However, I do have a question.
    I'm trying to access an Oracle store with JDBC.
    However, in my code, certain classes and such cannot
    be resolved; i.e. I am missing an import or two. So,
    what do I need to set on my classpath, if that is
    necessary (I have JRE 1.5.0_06, which includes JDBC,
    right?), and what files do I need to import?Includes all the java.sql interfaces, but not the Oracle implementation. You need to download that from Oracle:
    http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html
    Put that ojdbc14.jar in your project's CLASSPATH. You do not need to import any Oracle-specific classes.
    Let me give a quick example. When I type this:
    Connection connection = null;Connection cannot be resolved. Sounds like you need to re-read the JDBC tutorial.
    So my question is,
    what must I import to my Java class in order to use
    this effectively?You don't need to import, but you do need to load the Oracle JDBC driver class and then get a Connection from the DriverManager, just as all the tutorials show you.
    %

  • Can anyone guide me of using LDAP with JSP?

    I am a beginner in java. Plz post your answers in a simple and easy manner and explain it clearly. I am doing a project for which I require to use LDAP in JSP.

    I assume he wants to use LDAP to authenticate user logon in a JSP application.
    There are a few ways, JNDI being one. But a simpler method might be to see if this library works for you:
    http://www.mozilla.org/directory/javasdk.html
    HTH.

  • How to call BULK COLLECT using JDBC in JSP?

    Hi
    I am using BULK COLLECT instead of CURSOR in my Stored Procedure.
    How to use these stuff in JDBC.
    If i am using CURSOR means
    cs.registerOutParameter(1,oracle.jdbc.driver.OracleTypes.CURSOR);
    is used.
    Which types i have to use?
    I am retriving morethan one record using FOR. LOOP in SP and before that
    BULK COLLECT is used in SELECT query..
    Can you give jsp code for this?
    Thanks

    you may find related sample jdbc code on otn - http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html
    Best regards.

  • How to use SOAP with JSP (New to SOAP)

    Hi,
    i had a sch assignment(a set of JSPs)............anyone know how i can go about using soap for the encoding of data ? cos i had read up some books but i'm not sure how to go about implementing it !!!!! Anyone can help me?
    Regards,
    khim

    Hey,
    Just trying to understand the assignment objective:
    You have a SOAP message or some web-service that replies with SOAP messages?
    You have been asked to write a JSP that (queries this web-service and) retrieves the SOAP encoded data and transform it into XHTML (by whatever method you want) using XSLT?
    Is this the situation?
    If it is you will need to get the DTD or XSD of the SOAP message you will be displaying. This will tell you what elements to expect, what attributes they have and their sequencing.
    Then your problem is just the XSL style sheet. Here is a link if you do not kow much about XSL:
    http://www.w3schools.com/xsl/default.asp
    To perform the transform you can either use JSTL tags or you can use a Bean... I would suggest the JSTL tags.
    I hope the advice is not too late.
    Warm regards,
    Darren

  • Using JavaBean with JSP...will not work no matter what

    Hi guys. Sorry that this is such a common, newb question, but I don't know where else to turn.
    I'm new to web application development, Tomcat, and JSP. I'm trying to use a simple JavaBean in a JSP to store some user information. The JSP is located in $CATALINA_HOME\webapps\art , and the UserBean I'm trying to use is in $CATALINA_HOME\webapps\art\WEB-INF\classes . I've tried adding a context in the Tomcat server.xml file, but nothing seems to work, even putting the .class file into the \art directory along with the JSP. The error I get is the following:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 1 in the jsp file: /welcome.jsp
    Generated servlet error:
    [javac] Compiling 1 source file
    C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\art\welcome_jsp.java:43: cannot resolve symbol
    symbol : class UserBean
    location: class org.apache.jsp.welcome_jsp
    UserBean user = null;
    ^
    The source code is:
    welcome.jsp
    <%@ page import="java.sql.*" %>
    <jsp:useBean id="user" class="UserBean" scope="session"/>
    <html>
    <head>
    <title>Art Webapp Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <h1>Art Site</h1><br><br>
    <h3>Welcome Page</h3><br><br>
    <%
         user.setUsername("joe");
    user.setTitle("admin");
    %>
    </body>
    </html>
    UserBean:
    public class UserBean {
    private String username = null;
    private String title = null;
    public UserBean()
         this.username = null;
         this.title = null;
    public String getUsername()
         return this.username;
    public String getTitle()
         return this.title;
    public void setUsername(String inName)
         this.username = inName;     
    public void setTitle(String inTitle)
         this.title = inTitle;     
    }//UserBean
    Thanks for any and all help anyone could give me about this. It seems such a simple thing, to get a JavaBean working in a JSP...and it's very frustrating to have it NOT work when it seems I've done everything possible to get it to.

    Ok, I figured out what the problem was. My Bean was not a part of any specific package. It was never made clear to me that Beans are required to be a part of some package...I had no idea (though they always put them in packages in the tutorials, you think I would have picked up on it!).
    So I just added the following line to the Bean:
    package com.art;
    Then compiled it and copied the .class file to CATALINA_HOME\webapps\art\WEB-INF\classes\com\art
    Ta-da
    Thanks for the help and sorry for taking up space on this board.
    -Matt

  • Using JDBC with Visual Studio J++ doesn't work.

    G'day all,
    I am trying to create an applet that extracts data from an Access 2000 database, which is then displayed to the applet. Currently I am using Visual Studio J++ 6.0 as my development platform.
    I am having trouble trying to connect to my Access 2000 database, and I'm searching for some example code on how to do this.
    I'm pretty much a Java newbie, so all my attempts have failed. Also since all the example code I have is for a JDK implementation I'm not sure if my J++ complier is throwing an error on the basis that the code is not Misro$oft.
    Does anyone know where I can source code for such a solution, for connection to an Access 2000 database under a J++ 6.0 compiler?
    Any details would be greatly appreciated.

    Ripperjack,
    You're limited by the lack of support for the java standard in Microsoft's J++ 6.0's VM. I tried to get JDBC to work for a while in J++ and was unable to. I finally broke down and wrote the thing using ADO. The ADO interface is very intuative for ADO programmers and in fact the syntax is similar to JDBC.
    Later I regretted using J++ because I wanted to make the code portable and relieve my reliance on the Microsoft libraries. I rewrote some of my applications using JDK 2 and JDBC, and am currently rewriting the rest. You can use the ODBC-JDBC bridge with JDK 2 and get to that Access database.
    -Ryan

  • Using jdbc with oracle-for-win95

    i am using oracle thin driver to connect my java code with oracleforwin95 i think it is called as personal oracle, while getting conection DriverManager.getConection("drivername@host:port(1521):sid","user","password") there is no sid for oracleforwin95 if i keep it blank i get an error connection refused some thing like that even i cannot use dsn for connection what is the problem should i use another driver if yes which one it is and from where it can be downloaded, or should i need to configure my oracle. please help me.

    This is my code given below
    import java.sql.*;
    public class Oconnection
         Connection conn;
         Statement st;
         PreparedStatement pst,pstissue,pstret,pstbook;
         public Oconnection()
              try
                   Class.forName("oracle.jdbc.driver.OracleDriver");
                   conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","manager");
              catch(Exception ex)
                   System.out.println(ex.getMessage());
                   ex.printStackTrace();
         public static void main(String args[])
              new Oconnection();
    *****************************************************8
    Error
    C:\Library>java Oconnection
    Io exception: The Network Adapter could not establish the connection
    java.sql.SQLException: Io exception: The Network Adapter could not establish the
    connection
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:169)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:211)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:324)
    at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:266)
    at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja
    va:365)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
    at java.sql.DriverManager.getConnection(DriverManager.java:517)
    at java.sql.DriverManager.getConnection(DriverManager.java:177)
    at Oconnection.<init>(Oconnection.java:17)
    at Oconnection.main(Oconnection.java:39)
    I am using Oracle for win95 or i think it is oarcleforwin98 .
    The sid of my database i found through query given by you was orcl, what changes soulh i do int he code so that it works.

Maybe you are looking for

  • BAPI_INSPECTIONPLAN_CREATE

    Hi All, I am using BAPI_INSPECTION PLAN_CREATE to create some inpection plans. BAPI is running successfully. I am passing the following values in to the bapi. Task and Operations When i execute the BAPI it is returning message type S(successful) but

  • Poster Frames

    I have set a Poster Frame to a Frame near the end of a 5 min, Video. When I open the movie in QT it starts at the poster frame and only plays the last few seconds of the video. How can I Set a Poster frame near the end but have the video start playin

  • Photoshop element 1.0 and internet explorer10

    Bonjour, Je possède photoshop element 1.0 surCD avec numérode série. Lors de l'installation sur un nouveau PC, ils'arrête avec le message "ne fonctionne qu'avec internet explorer  > 4.0" alors que je possède internet explorer 10. Comment l'installer

  • How to add disclaimer on smtp server and use it using utl_smtp.

    We use utl_smtp to send emails. The requirement is to add a disclaimer on smtp server so that any outgoing emails sent using utl_smtp should have this disclaimer. Is that possible and how do we acheive this? --Thank you for any suggestions.          

  • Adding and Removing Tunes from iPod nano

    I am a 68 year old man who has loved music for many years and has an extensive music collection so my kids gave me an iPodnano for Christmas 2007. I hardly touched it for over a year because of fear of and unfamiliarity with new technologies but rece