Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

connection to postgresql

sagrud13sagrud13 Posts: 1Member
i have to connect to Postgresql to populate a listbox... i used the following jsp and html code... but i get an internal error.
I m a newbie in programming... so pls let me kno the error in this code.

my.jsp

<%@ page import="java.sql.*" %>
<%@ page language="java" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="java.util.*" %>

<%
PrintWriter pw = response.getWriter();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String queryText = null;
%>

<%
queryText = "select state_name from state_project"

try {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/india_data","postgres","postgres");
return(1);
stmt = conn.createStatement();
rs = stmt.executeQuery(queryText);
List x= new ArrayList();
while(rs.next()){
request.setAttribute("state_name", rs.getString(2));}
pw.println("state_name" + " "+"<br>");
x.add(rs.getString(2));
}
request.setAttribute("state_namel",x);}
catch(Exception e) {
pw.println("Error.."+e);
}

%>




my html form is



<%
int i=1;
int nouser
List xlist;%>
<%
xlist=(ArrayList)request.getAttribute("state_namel");
nouser = xlist.size();
%>



---Select Name---

Iterator userit= xlist.iterator();
while(userit.hasNext()){
while(i<=nouser()){%>
"><%=userit.next()%>
<%
i++;
}
}
%>





Sign In or Register to comment.