|
-
Nov 20th, 2009, 12:45 AM
#1
Thread Starter
Hyperactive Member
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.
-
Nov 20th, 2009, 02:27 PM
#2
Re: Servlet + JSP + MVC + Database
Here's is a code snippet to connect to a database through JSP:
java Code:
String driver = "org.apache.derby.jdbc.EmbeddedDriver"; String dbName="C:\\databases\\mydb"; String connectionURL = "jdbc:derby:" + dbName; try { Class.forName(driver); } catch(java.lang.ClassNotFoundException e) { e.printStackTrace(); } try { conn = DriverManager.getConnection(connectionURL); } catch (Throwable e) { e.printStackTrace(); } 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. 
-
Nov 25th, 2009, 02:43 AM
#3
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|