Results 1 to 3 of 3

Thread: Servlet + JSP + MVC + Database

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Question Servlet + JSP + MVC + Database

    Hello,

    I wish to retrieve the value from the database (PostgreSQL) and store in the drop down option using Servlet and JSP with MVC architecture. In PHP we did the same like below format.

    <?php

    // php code of retrieve the data from database goes here

    ?>

    <html>

    html coding goes here
    we hold the values retrieve from database above will come under the drop down option

    </html>

    But when I am trying to call and create the database connection I am getting the error something like 'cannot identify the class'.

    Please help me to find the solution.

    Thanks a lot in advance.

    Thanks & Regards.

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Servlet + JSP + MVC + Database

    Here's is a code snippet to connect to a database through JSP:

    java Code:
    1. String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    2.         String dbName="C:\\databases\\mydb";
    3.         String connectionURL = "jdbc:derby:" + dbName;
    4.        
    5.         try {
    6.             Class.forName(driver);
    7.         } catch(java.lang.ClassNotFoundException e) {
    8.             e.printStackTrace();
    9.         }
    10.        
    11.         try {
    12.             conn = DriverManager.getConnection(connectionURL);
    13.         } catch (Throwable e) {  
    14.             e.printStackTrace();
    15.         }
    16.  
    17.         stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

    This is for a Derby database, not PostgreSQL, but I'm assuming if you find the appropriate driver, it shouldn't require many changes!


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Question Re: Servlet + JSP + MVC + Database

    Hello Sir,

    Thanks a lot for the kind reply. Here I like to know if I wish to retrieve the value from the database and populate the List with it when the .jsp page will load first time. Where should I put the code and how to make it with Servlet and others. Please help.

    Thanks & Regards.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width