我正在尝试从mysql获取数据并以xml格式设置所有数据,但我无法执行此任务。我的代码是:
abc.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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
try
{
Connection connection=DBCreation.getConnection();
Stirng query="select latitude,longitude,time from jam_info";
Statement stmt=connection.createStatement();
ResultSet rs=stmt.executeQuery(query);
%></body>
</html>
<%@ page contentType="text/xml" %>
<markers>
<marker>
<latitude></latitude>
<longitude></longitude>
<time>100</time>
</marker>
</markers>
我认为这是错误的。请指导我。
答案 0 :(得分:1)
你可以做这样的事情,getXXX方法将取决于持有该值的列的类型。
<%@ page language="java" contentType="text/xml; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
Connection connection=DBCreation.getConnection();
Stirng query="select latitude,longitude,time from jam_info";
Statement stmt=connection.createStatement();
ResultSet rs=stmt.executeQuery(query);
response.setContentType("text/xml");
out.println("<markers>");
while(rs.next()) {
out.println("<marker>");
out.println("<latitude>" + rs.getXXX("latitude") + "</latitude>");
out.println("<longitude>" + rs.getXXX("longitude") + "</longitude>");
out.println("<time>" + rs.getXXX("time") + "</time>");
out.println("</marker>");
}
out.println("</markers>");
%>
希望这有帮助。