我正在尝试使用简单查询填充下拉列表。我尝试在控制台上打印查询输出,它工作正常,但它似乎没有填充下拉列表。
这是我的java文件
package testpkg;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.*;
public class Facility
{
public Statement st;
public void get_connection()
{
try
{
Class.forName("oracle.driver.OracleDriver");
}
catch(ClassNotFoundException e)
{
System.out.println("Oracle JDBC driver missing. Connection to Database failed!!");
e.printStackTrace();
return;
}
System.out.println("Oracle JDBC Driver Registered");
Connection con = null;
try
{
con = DriverManager.getConnection("jdbc:oracle:thin:@10.201.301.111:1521:PIC1","ID","PASS");
}
catch(SQLException e)
{
System.out.println("Connection Failed!! Check console for error code!!");
e.printStackTrace();
return;
}
if(con !=null)
{
System.out.println("Database Connection Successful!");
}
try
{
con.close();
}
catch(Exception e){}
}
}
这是另一个java类
package testpkg;
import java.sql.*;
public class state extends Facility
{
public ResultSet getStates()
{
ResultSet rs = null;
try
{
get_connection();
rs= st.executeQuery("select org.org_name from organization org");
}
catch (Exception e){}
return (rs);
}
}
这是JSP代码
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import = "java.io.PrintWriter" %>
<%@page import="java.sql.*"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.SQLException"%>
<%@page import="testpkg.state"%>
<%
try
{
state s = new state(); //initializing the state.java class
ResultSet rs= s.getStates(); //calling the method getStates from state.java
String data;%>
<select id="combos" name="org">
<%while(rs.next())
{
data = rs.getString("ORG_NAME");%>
<option value= "<%=data %>"> <%=data%> </option>
<%}%>
</select>
<%}
catch(Exception e){}%>