Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to avoid java code in jsp file. but i couldnt figure the solution. so i ended up mixing the codes :( how can i divide this code? PLEASEEE HELPPP...

Thank you very much.

What I have tried:

<select>
<option selected disabled>Lecturers Name</option>
<%
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:xe";
String username="sys as sysdba";
String password="sys";
String query="select lecturerFullname from lecturer";
Connection con=DriverManager.getConnection(url,username,password);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{

%>

<option><%=rs.getString("lecturerFullname") %></option>

<%

}
%>
<%
rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>

</select>
Posted

1 solution

Hi.
To avoid spending much more time while maintaining your code than developing it, you should thing in a MVP arch.
Start by developing, for example, a servlet (Controller) that uses a wrappered Java (Bean) class (Model) to get data from DB. Later, in your JSP (View) you can ask controller for data to show at frontend.
You can get a lot of examples at Internet and different frameworks to use, or maybe you prefer build it from scratch, it's your decision.
But if you need more information, please count on us.

Here you are an example :
MVC in JSP - javatpoint[^]

Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900