我必须在jsp中从数据库中创建一个饼图。我的数据库由字符串值组成如何执行此操作,请任何人答复 下面是我的代码。但它只接受整数值,我必须使用字符串值
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*,java.sql.*" %>
<%@ page import="com.google.gson.Gson"%>
<%@ page import="com.google.gson.JsonObject"%>
<%
Gson gsonObj = new Gson();
Map<Object,Object> map = null;
List<Map<Object,Object>> list = new ArrayList<Map<Object,Object>>();
String dataPoints = null;
try{
Class.forName("com.mysql.jdbc.Driver");
String user_name = "root";
String password = "test123$";
Connection con = DriverManager.getConnection("jdbc:mysql://192.168.1.7:3306/omaxdb", user_name,
password);
Statement statement = con.createStatement();
String xVal, yVal;
ResultSet resultSet = statement.executeQuery("select * from datapoints");
while(resultSet.next()){
xVal = resultSet.getString("x");
yVal = resultSet.getString("y");
map = new HashMap<Object,Object>(); map.put("x", Double.parseDouble(xVal)); map.put("y", Double.parseDouble(yVal)); list.add(map);
dataPoints = gsonObj.toJson(list);
}
con.close();
}
catch(SQLException e){
out.println("<div style='width: 50%; margin-left: auto; margin-right: auto; margin-top: 200px;'>Could not connect to the database. Please check if you have mySQL Connector installed on the machine - if not, try installing the same.</div>");
dataPoints = null;
}
%>