PDA

Click to See Complete Forum and Search --> : Servlet + JSP + MVC + Database


systech44
Nov 19th, 2009, 11:45 PM
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.

manavo11
Nov 20th, 2009, 01:27 PM
Here's is a code snippet to connect to a database through JSP:

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!

systech44
Nov 25th, 2009, 01:43 AM
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.