Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 连接到MySQL数据库时没有动画_Javascript_Mysql_Html_Jsp - Fatal编程技术网

Javascript 连接到MySQL数据库时没有动画

Javascript 连接到MySQL数据库时没有动画,javascript,mysql,html,jsp,Javascript,Mysql,Html,Jsp,我试图根据从MySQL数据库检索到的x轴和y轴的位置,在html5画布中移动一个对象。当我在没有数据库的情况下运行代码时,代码正在运行。但是在将页面连接到数据库之后,没有任何移动 请告诉我哪里出了问题。或者还有其他的方法吗 请不要建议切换到PHP index.jsp <%@page center code here`ontentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <

我试图根据从MySQL数据库检索到的x轴和y轴的位置,在html5画布中移动一个对象。当我在没有数据库的情况下运行代码时,代码正在运行。但是在将页面连接到数据库之后,没有任何移动

请告诉我哪里出了问题。或者还有其他的方法吗

请不要建议切换到PHP

index.jsp

<%@page center code here`ontentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>test</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <style type="text/css">
       #canvas{
           border: #666 2px solid;
       }
    </style>
    <script type="text/javascript">

       function draw(x,y)
       {
          var canvas=document.getElementById('canvas');
          var ctx=canvas.getContext('2d');
          ctx.save();
          ctx.clearRect(0,0,550,400);
          ctx.fillStyle="rgba(0,200,0,1)";
          <%@include file="connectToDB.jsp"%>
          <%
            int a,b;
            String sql="SELECT * FROM movement_details";
            try{
               rs = stmt.executeQuery(sql);
               while (rs.next()) 
              {
                 a=Integer.parseInt(rs.getString(4));
                 b=Integer.parseInt(rs.getString(5));
           %>
            var x="<%=a%>";
            var y="<%=b%>";

            ctx.fillRect(x,y,30,30);
            ctx.restore();  

           setTimeout(100);
        <%
             }
          }catch (Exception e) 
          {
            e.printStackTrace();
          }finally 
          {
              try { if (rs != null) rs.close(); } catch (SQLException e) { e.printStackTrace(); }
             try { if (stmt != null) stmt.close(); } catch (SQLException e) { e.printStackTrace(); }
             try { if (conn != null) conn.close(); } catch (SQLException e) { e.printStackTrace(); }
         }
         %>
      }

  </script>
</head>

<body onload="draw();">
    <canvas id="canvas" width="550" height="400"></canvas> 

    <!--<button onclick="draw('x','y');">Draw</button>-->

</body>
</html>
这是我将页面连接到数据库的文件

connectToDB.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<%@page import="java.io.*" %>
<%@page import="javax.sql.*" %>
<%@page import="java.sql.Connection" %>
<%  String str = " ";
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    //out.print(" "+session.getAttribute("empID"));
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    String connectionUrl = "jdbc:mysql://localhost:3306/test2";
    String connectionUser = "root";
    String connectionPassword = "root";
    conn = DriverManager.getConnection(connectionUrl, connectionUser, connectionPassword);
    stmt = conn.createStatement();%>

DB绑定是否正常工作?日志中有异常吗?@Jozef没有,没有异常。我还试着从DB打印值,它正确地打印了所有的值。所以绑定中没有问题。