简体   繁体   中英

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.

<%@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(). 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 runs entirely on the user's browser; so even if JS had a built-in database querying library, chances are the database would refuse the direct connection. 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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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