insert data in table of cities

This commit is contained in:
lukas-heiligenbrunner 2019-11-15 13:30:44 +01:00
parent 36caaa214b
commit e292df8bb8
4 changed files with 51 additions and 39 deletions

View File

@ -12,5 +12,8 @@
<orderEntry type="library" name="mysql-connector-java-5.1.44-bin" level="project" />
<orderEntry type="library" name="mysql-connector-java-5.1.44-bin" level="project" />
<orderEntry type="library" name="org.eclipse.paho.client.mqttv3-1.2.1" level="project" />
<orderEntry type="library" name="gson-2.8.6-javadoc" level="project" />
<orderEntry type="library" name="gson-2.8.6" level="project" />
<orderEntry type="library" name="gson-2.8.6-sources" level="project" />
</component>
</module>

View File

@ -335,20 +335,6 @@
</tr>
</thead>
<tbody id="location-table-data">
<tr>
<td>Trident</td>
<td>Internet
Explorer 4.0
</td>
<td>Win 95+</td>
</tr>
<tr>
<td>Trident</td>
<td>Internet
Explorer 5.0
</td>
<td>Win 95+</td>
</tr>
</tbody>
<tfoot>
<tr>
@ -432,19 +418,6 @@
<!-- DataTables -->
<script src="lib/AdminLTE/plugins/datatables/jquery.dataTables.js"></script>
<script src="lib/AdminLTE/plugins/datatables-bs4/js/dataTables.bootstrap4.js"></script>
<script>
$(function () {
$("#example2").DataTable();
$('#example1').DataTable({
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"info": true,
"autoWidth": false,
});
});
</script>
</body>
</html>

View File

@ -11,13 +11,25 @@ $(document).ready(function () {
}, 'json');
$.post('/senddata/wastedata', 'action=getAllCities', function (data) {
for (var i = 0; i < data.size; i++) {
console.log(data);
for (var i = 0; i < data.data.length; i++) {
$('#location-table-data').append("<tr>" +
"<td>" + data[i].city + "</td>" +
"<td>" + data[i].zone + "</td>" +
"<td>" + data[i].wastetype + "</td>" +
"<td>" + data.data[i].cityname + "</td>" +
"<td>" + data.data[i].zone + "</td>" +
"<td>" + data.data[i].wastetype + "</td>" +
"</tr>");
}
//todo entweda 1 od 2
$("#example2").DataTable();
$('#example1').DataTable({
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"info": true,
"autoWidth": false,
});
}, 'json');
@ -36,9 +48,9 @@ $(document).ready(function () {
var cityname = $("#new_city_cityname").val();
var zonename = $("#new_city_zonename").val();
var wastetype = $("#dropdown-wastetype").html();
console.log("storing: "+cityname + "--" + wastetype + "in db");
console.log("storing: " + cityname + "--" + wastetype + "in db");
$.post('/senddata/wastedata', 'action=newCity&wastetype=' + wastetype +"&cityname="+cityname+"&wastezone="+zonename, function (data) {
$.post('/senddata/wastedata', 'action=newCity&wastetype=' + wastetype + "&cityname=" + cityname + "&wastezone=" + zonename, function (data) {
console.log(data);
}, 'json');
@ -50,8 +62,6 @@ $(document).ready(function () {
});
$('.btn-addtolist').click(function () {
console.log("added new row to table");
$('#addtable-body').append("<tr>" +
@ -71,7 +81,7 @@ $(document).ready(function () {
for (var i = 0; i < wastetypearr.length; i++) {
console.log(wastetypearr[i].innerHTML);
$.post('/senddata/wastedata', 'action=senddata&wastetype=' + wastetypearr[i].innerHTML +"&wastetime="+wastetime[i].innerHTML+"&wasteregion="+wasteregionarr[i].innerHTML+"&wastezone="+wastezonearr[i].innerHTML, function (data) {
$.post('/senddata/wastedata', 'action=senddata&wastetype=' + wastetypearr[i].innerHTML + "&wastetime=" + wastetime[i].innerHTML + "&wasteregion=" + wasteregionarr[i].innerHTML + "&wastezone=" + wastezonearr[i].innerHTML, function (data) {
console.log(data);
}, 'text');
}

View File

@ -1,5 +1,6 @@
package com.wasteinformationserver.website.datarequests;
import com.google.gson.Gson;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB;
import com.wasteinformationserver.website.basicrequest.PostRequest;
@ -11,6 +12,7 @@ import java.util.HashMap;
public class DataRequest extends PostRequest {
@Override
public String request(HashMap<String, String> params) {
String result = "";
switch (params.get("action")) {
case "newCity":
Log.debug(params.toString());
@ -35,10 +37,34 @@ public class DataRequest extends PostRequest {
break;
case "getAllCities":
// TODO: 15.11.19 database call to get all data and store it as json.
// TODO: 15.11.19 database call to get all data and store it as json.
JDCB jdcbc = new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation");
Gson gson = new Gson();
StringBuilder builder = new StringBuilder();
ResultSet sett = jdcbc.executeQuery("select * from cities");
Log.debug(sett.toString());
builder.append("{\"data\":[");
try {
while (sett.next()) {
builder.append("{\"cityname\":\""+sett.getString("name")+"\"");
builder.append(",\"wastetype\":\""+sett.getString("wastetype")+"\"");
builder.append(",\"zone\":\""+sett.getString("zone")+"\"}");
if (!sett.isLast()){
builder.append(",");
}
// System.out.println(sett.getString("name"));
}
} catch (SQLException e) {
e.printStackTrace();
}
builder.append("]}");
result= builder.toString();
Log.debug(result);
break;
}
return "";
return result;
}
}