简体   繁体   English

Javascript错误:SyntaxError:缺少; 声明前

[英]Javascript Error: SyntaxError: missing ; before statement

I have the following code snippet. 我有以下代码片段。 I have tried all the possible things mentioned on StackExchange but am unable to spot the error in my code. 我已经尝试了StackExchange上提到的所有可能的方法,但是无法在我的代码中发现错误。

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8" />
<title>Twitter Mapper</title>
<link rel="stylesheet" href="styles/styles.css">

<script type="text/javascript"
    src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
</head>
<body>

    <br />
    <br />
    <div id="map-canvas" align="center"></div>

    <script src="scripts/heatmap.js"></script>
    <script src="scripts/gmaps-heatmap.js"></script>
    <script>
    window.onload = (function() {

        alert("hi");
        // map center
        var myLatlng = new google.maps.LatLng(25.6586, -80.3568);
        // map options,
        var myOptions = {
            zoom : 3,
            center : myLatlng
        };
        // standard map
        map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
        // heatmap layer
        heatmap = new HeatmapOverlay(map, {
            // radius should be small ONLY if scaleRadius is true (or small radius is intended)
            "radius" : 2,
            "maxOpacity" : 1,
            // scales the radius based on map zoom
            "scaleRadius" : true,
            // if set to false the heatmap uses the global maximum for colorization
            // if activated: uses the data maximum within the current map boundaries 
            //   (there will always be a red spot with useLocalExtremas true)
            "useLocalExtrema" : true,
            // which field name in your data represents the latitude - default "lat"
            latField : 'lat',
            // which field name in your data represents the longitude - default "lng"
            lngField : 'lng',
            // which field name in your data represents the data value - default "value"
            valueField : 'count'
        });
    });

        function populateMap() {

            Connection conn = null; 
             Statement stmt = null; 
             ResultSet rset = null; 
             try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                conn = DriverManager.getConnection("jdbc:mysql://localhost:8889/mysql", 
                                                   "", "");
                stmt = conn.createStatement();
                // dynamic query
                rset = stmt.executeQuery ("SELECT * FROM tweets");
               //return (formatResult(rset));
             } finally {
                 if (rset!= null) rset.close(); 
                 if (stmt!= null) stmt.close();
                 if (conn!= null) conn.close();
             }

        };


    </script>
</body>
</html>

The line for the error is shown to be as the first line in function populateMap(). 错误行显示为函数populateMap()中的第一行。 Please help. 请帮忙。

在Javascript中,您不使用类型声明变量,而是使用var:

var conn = null, stmt = null, rset = null; 

The commenters are right, but looking at the lines past that, that may not be your only issue. 评论者是正确的,但从那以后看,这可能不是您唯一的问题。 Unless this is some really powerful JavaScript library I don't know about that somehow gets included in Google's map scripts, then I don't think the JDBC things you're trying to do actually exist. 除非这是一个真正强大的JavaScript库,否则我不知道该库是否以某种方式包含在Google的地图脚本中,否则我不认为您尝试做的JDBC事情实际上是存在的。

JavaScript runs entirely on the user's browser; JavaScript完全在用户的浏览器上运行; so even if JS had a built-in database querying library, chances are the database would refuse the direct connection. 因此,即使JS具有内置的数据库查询库,数据库也有可能拒绝直接连接。 You likely need to create that database query on the server as an AJAX endpoint that converts its data into a text format like JSON, and lets the JavaScript request that using AJAX. 您可能需要在服务器上作为AJAX端点创建该数据库查询,该数据库查询将其数据转换为JSON之类的文本格式,并让JavaScript使用AJAX进行请求。

I can't go over all of that in a single post, but you have a lot of reading up to do. 我无法在一个帖子中讨论所有这些内容,但是您需要做很多阅读工作。 I'd start with a basic tutorial on AJAX, or the differences between JavaScript and Java (it's not just night and day; it's night and tabletop tennis). 我将从有关AJAX的基本教程开始,或者从JavaScript和Java之间的区别开始(不只是白天和黑夜;还有晚上和乒乓球网球)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM