connection to postgresql - Programmers Heaven

Howdy, Stranger!

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

Categories

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.