i need to connect the jsp file with the database. i did connect it but the thing is that now the actionscript that i created won't read the value from the database. when i run the movie, (because i trace the value) the output will state as undefined instead of the values from the database.
below is my jsp code:
Code:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<%@ include file="mysqlConfig.jsp" %>
<%
Connection connection = null;
String str="";
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(s1_db, db_user, db_pw);
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("SELECT * FROM mapping");
//String[][] data = new String[11][10];
int x = 0;
while (rs.next()) {
//noinspection UnusedAssignment
str = str + "&Longitude" + x + "=" + rs.getString("Longitude") + "&Latitude" + x + "=" + rs.getString("Latitude") +
"&Angle" + x + "=" + rs.getString("Angle") + "&" + "<br>";
x++;
}
out.println(str);
} catch(ClassNotFoundException cnfe){
System.out.println("Database driver not found:" + cnfe.getMessage());
} catch(SQLException sqlexception){
System.out.println("Error opening the db connection: " + sqlexception.getMessage());
} finally {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
%>
and the one below is my actionscript code:
HTML Code:
stop();
_global.serverURL = "http://172.16.218.47:8080/uas_admin/";
var intervalTime:Number; //setInterval
var mUnit:Array = new Array();
var targetIndex:Number = 0;
this.initMap();
//this.createEmptyMovieClip("line_mc", 1); //creating the line
//line_mc.lineStyle(2, 0xFF00FF, 30);
//this.attachMovie("arrowmc", "arrowmc", this.getNextHighestDepth()); //inserting the mc
var move_int = setInterval(moveChaser,500); //setting time delay between movements
function moveChaser(){
trace(updated);
if(updated == true){
for (var n = 0; n < mUnit.length; n++) {
trace("Value "+ n + ": (" + mUnit[n].mLong + ", " + mUnit[n].mLati + ")" );
}
}
}
// function to call JSP file to access database for latest MGR and heading angle
function initMap():Void {
var send_lv:LoadVars = new LoadVars();
var rec_lv:LoadVars = new LoadVars();
var updated:Boolean = false;
// Battlescape to receive data from test.mapping using main.jsp
send_lv.sendAndLoad(_global.serverURL + "mine.jsp", rec_lv, "POST");
rec_lv.onLoad = function(success:Boolean) {
if (success) {
var i:Number = 0;
while (rec_lv["Longitude"+i] != null){
mUnit[i] = new Mappie(rec_lv["Longitude"+i], rec_lv["Latitude"+i], rec_lv["Angle"+i]);
i++;
}
updated = true;
}
}
}