gpt4 book ai didi

java - 列表连接到数据库不显示数据JSP

转载 作者:行者123 更新时间:2023-11-29 11:29:14 25 4
gpt4 key购买 nike

我的页面不显示选项列表中的数据,数据输入来自数据库中的表格,显示寄存器的数量,但白色不显示数据。我想从列表中选择一个选项....

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page language="java"%>
<%@page import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<table id="cliente" border="1" class="tabla">
<form method="get" action="generaReporte" id="forminicio">
<tr><th class="thCliente">Febrero</th></tr>
<th class="thCliente">Fecha </th>
<th class="thCliente">Cliente</th>
<th class="thCliente">Actividad</th>
<th class="thCliente">Horas</th>

<th>
<%//establecemos la conexion a la BD para mostrar los clientes
try
{
Connection conexion = null;
Statement sentencia = null;
ResultSet resultado = null;
Class.forName("com.mysql.jdbc.Driver");
String cadenaConexion = "jdbc:mysql://localhost:3306/LOGIN";
String usuario = "root";
String clave = "5533834712";
conexion = DriverManager.getConnection(cadenaConexion,usuario,clave);
if(!conexion.isClosed())
{
sentencia = conexion.createStatement();
resultado = sentencia.executeQuery("select * from cliente");
out.println("<select style='width:300px;border:1px;font-family:sans-serif;font-size: 16px;' name='select'>");
out.println("<option >Selecciona el Cliente</option>");
while(resultado.next())
{
String nombre = resultado.getString("Nombre");
//String id = resultado.getString("id");
out.println("<option value='"+nombre+"'></option>");
}
out.println("</select>");
conexion.close();
}
else
out.println("fallo");
}
catch(Exception e)
{
out.println("Error"+e);
e.printStackTrace();
}
%>
</th>
</tr>
</form>
</body>
</html>

最佳答案

使用这样的东西应该可以。

<option value='"+nombre+"'> nombre </option>

关于java - 列表连接到数据库不显示数据JSP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37693918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com