Using a JSP created data set in d3

279 views
Skip to first unread message

ziffification

unread,
Oct 20, 2016, 9:56:24 PM10/20/16
to d3-js
I have the code below producing a dataset myResultSet 
how do I get that dataset to use in d3 ...Ive been stumbling around trying to figure this out all day




<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.* " %>
<%@ page import="java.io.*" %>
<%@page import="java.io.File"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.net.URL"%>
<%@page import="java.io.FileReader"%>
<%@page import="java.io.BufferedReader"%>


<%
           
String jspPath = session.getServletContext().getRealPath("/DashBoard");
           
String txtFilePath = jspPath+ "\\1.sql";
           
BufferedReader reader = new BufferedReader(new FileReader(txtFilePath));
           
StringBuilder sb = new StringBuilder();
           
String line;


           
while((line = reader.readLine())!= null)
           
{
                sb
.append(line+"\n");
           
}




String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:PRD_UDW";
String username = "<USERNAME>";
String password = "<PASSWORD>";
String myDataField = null;
String myQuery = sb.toString();




Connection myConnection = null;
PreparedStatement myPreparedStatement = null;
ResultSet myResultSet = null;
Class.forName(driver).newInstance();
myConnection
= DriverManager.getConnection(url,username,password);
myPreparedStatement
= myConnection.prepareStatement(myQuery);
myResultSet
= myPreparedStatement.executeQuery();
%>




the data set looks like this 

College_Admin_Unit Department Department_Code Employee_Category Employee_Status_Code Employee_Status Designation Fiscal_Year Central_Fund_Indicator Account_Code Job_Code Job_Description FTE
Facilities Management FMD P&D Info Infrastruct Serv 1203 Support A Active Non-Academic 2013/2014 N 11021871203602037000-9999 1458 Draftsperson 0.450000
Facilities Management FMD P&D Info Infrastruct Serv 1203 Support A Active Non-Academic 2014/2015 N 11011001203602037000-9999 1458 Draftsperson 0.550000
Facilities Management FMD P&D Info Infrastruct Serv 1203 Support A Active Non-Academic 2014/2015 N 11021871203602037000-9999 1458 Draftsperson 0.450000
Facilities Management FMD P&D Info Infrastruct Serv 1203 Support A Active Non-Academic 2015/2016 N 11011001203602037000-9999 1458 Draftsperson 0.550000
Facilities Management FMD P&D Info Infrastruct Serv 1203 Support A Active Non-Academic 2015/2016 N 11021871203602037000-9999 1458 Draftsperson 0.450000
Facilities Management FMD P&D Project Mgmt Office 1200 Administrative & Professional A Active Non-Academic 2012/2013 N 11011001200602027000-9999 1011 Administrator 0.260000
Facilities Management FMD P&D Project Mgmt Office 1200 Administrative & Professional A Active Non-Academic 2012/2013 N 11011001200602027000-9999 1050 Interior Designer 0.190000
Facilities Management FMD P&D Project Mgmt Office 1200 Administrative & Professional A Active Non-Academic 2012/2013 N 11011001200602027000-9999 1055 Manager 1.000000
Facilities Management FMD P&D Project Mgmt Office 1200 Administrative & Professional A Active Non-Academic 2012/2013 N 11021871200602027000-9999 1011 Administrator 1.740000

Curran

unread,
Oct 21, 2016, 9:39:11 AM10/21/16
to d3-js
Hello,

Probably the best way forward is to have your Java code generate a CSV string (putting commas between the values), then parse that string with d3.csvParse.

Maybe the simplest thing would be to have the JSP page render a CSV string, then use d3.csv from a separate page to load the data and parse it. From the visualization code perspective, it would be just like loading a static CSV file, but from the server perspective, the content of the HTTP response would be dynamically generated from your ResultSet.

Best regards,
Curran
Message has been deleted

ziffification

unread,
Oct 21, 2016, 11:36:25 AM10/21/16
to d3-js

ok I was trying to convert it to JSON as well dont suppose you have an example of doing via csv , I can seem to locate good examples?

ziffification

unread,
Oct 24, 2016, 1:03:35 PM10/24/16
to d3-js

   response.setContentType("text/csv");
   response.setHeader("Content-Disposition", "attachment; filename=MSmult_table.csv");
   out.println("College_Admin_Unit,Department,Department_Code,Employee_Category,Employee_Status_Code,Employee_Status,Designation,Fiscal_Year,Central_Fund_Indicator,Account_Code,Job_Code,Job_Description,FTE") ;
   while (myResultSet.next())
   {
     outstring = myResultSet.getString("College_Admin_Unit") + "," + myResultSet.getString("Department") + "," + myResultSet.getString("Department_Code") + "," + myResultSet.getString("Employee_Category") + "," + myResultSet.getString("Employee_Status_Code") + "," + myResultSet.getString("Employee_Status") + "," + myResultSet.getString("Designation") + "," + myResultSet.getString("Fiscal_Year") + "," + myResultSet.getString("Central_Fund_Indicator") + "," + myResultSet.getString("Account_Code") + "," + myResultSet.getString("Job_Code") + "," + myResultSet.getString("Job_Description") + "," + myResultSet.getString("FTE");
     out.println(outstring);
   }





Ok I did the above this creates a file in memory but how do i have it not download just reside in memory so i can operate on it using D# 
Reply all
Reply to author
Forward
0 new messages