Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
connection to postgresql Posted by sagrud13 on 6 Sept 2010 at 1:55 AM
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


<form name ="myform" action="my.jspx" method="GET"><nbr>
<%
int i=1;
int nouser
List xlist;%>
<%
xlist=(ArrayList)request.getAttribute("state_namel");
nouser = xlist.size();
%>


<select name="state" value="">
<option value="0">---Select Name---</option>

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







 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.