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