Datasource - what is wrong?

Datasource - what is wrong?

legalizeSINCE88legalizeSINCE88 Posts: 16Questions: 1Answers: 0
edited April 2014 in General
What is wrong with this?
It won´t work!

[code]


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;


public class getData extends HttpServlet {
private static final long serialVersionUID = 1L;

Connection con;
Statement stmt;
ResultSet rs;
int number;


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
JSONArray array = new JSONArray();
JSONObject obj = new JSONObject();

try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/ausgaben","admin","s3cret#");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM ausgaben");
ResultSetMetaData meta = rs.getMetaData();
number = meta.getColumnCount();


while(rs.next())
{
JSONArray a = new JSONArray();
a.add(rs.getString("Ausgaben"));
a.add(rs.getString("vom"));
a.add(rs.getString("Preis"));
array.add(a);
}

obj.put("sEcho", 3);
obj.put("iTotalRecords", number);
obj.put("iTotalDisplayRecords", number);
obj.put("aaData", array);

PrintWriter out = response.getWriter();
out.print(obj);


rs.close();
stmt.close();
con.close();

}catch(Exception e)
{
e.printStackTrace();
}

}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

}

[/code]


[code]
$(function(){

$('#tableExample').DataTable({
"sDom": 'TC<"clear">lfrtip',
"sAjaxSource": "getData",

"oTableTools": {
"sSwfPath": "Tabelle/TableTools/media/swf/copy_csv_xls_pdf.swf",
"aButtons": [
{
"sExtends": "collection",
"sButtonText": "save as",
"aButtons": [ "csv", "xls", "pdf" ]
},
'print'

]
}

});

});

[/code]

Replies

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Why are you output server-side processing information (sEcho etc) when you aren't using server-side processing?

    What is the data returned by `getData` ? Can you please link to a test case - as required in the forum rules.

    Allan
This discussion has been closed.