【问题标题】:Java web app + mySQL in-app on AzureAzure 上的 Java Web 应用程序 + mySQL 应用程序内
【发布时间】:2017-06-24 15:16:37
【问题描述】:

我在本地测试了一个由 servlet、html、js、css 和 MySql 数据库组成的 Web 应用程序。它完美运行,没有错误,没有异常,什么都没有。

现在,通过我的大学,我有机会免费测试 Microsoft Azure 的新 MySQL 应用内功能,我决定使用这项新功能将我的 Web 应用程序放在 Azure 上。

因此,在 Azure Dashbord 上,我选择了“Web App + MySQL”选项,并在随后的子菜单中选择了“MySQL in-app”选项。

在我的 Web 应用程序中,我使用 JDBC 将我的 Java servlet 连接到 Mysql 数据库。我知道我必须从 MYSQLCONNSTR_localdb 环境变量中获取数据库连接参数。我可以从 java servlet(使用 System.getenv("MYSQLCONNSTR_localdb"))和 Kudu 控制台(观察 data/mysql/MYSQLCONNSTR_localdb.txt 中的文件)获取这些参数。在这两种情况下,我看到相同的值,这些是:

Database=localdb;Data Source=127.0.0.1:51477;User Id=azure;Password=6#vWHD_$

我在我的 Java 类中将它们与 JDBC 一起使用:

public class DataBase {
    private final String driver = "com.mysql.jdbc.Driver";
    private final String nomeDB =   "localdb/"; 
    private final String urlDB =   "jdbc:mysql://127.0.0.1:51477/+nomeDB; 
    private final String usernameDB =  "azure";
    private final String passwordDB =  "6#vWHD_$"; 
    private Connection connection;

    public DataBase () {
        try {
            Class.forName(driver).newInstance();
            this.connection = DriverManager.getConnection(urlDB, usernameDB, passwordDB);
        }catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    ...

我可以通过 FileZilla FTP 在 Azure(在 /site/wwwroot/webapps)上部署我的 .war,但使用以下 URL:

fishingassistant.azurewebsites.net/FishingAssistantWebApp/

我可以看到我的网络应用程序的索引(一个登录页面),但是当我单击一个用于将用户名和密码发送到相关 servlet 的按钮时,我得到一个“HTTP 状态 500 -”,如下所示:

type Exception report

message

description The server encountered an internal error that prevented it from fulfilling this request.

exception

java.lang.NullPointerException
    it.classes.DataBase.checkUsernamePassword(DataBase.java:181)
    it.servlets.SigninServlet.doPost(SigninServlet.java:47)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

这个异常描述了这行代码(第 181 行):

// verifica validità username e password (loro presenza nella tab Utente)
public ResultSet checkUsernamePassword(String username, String password) throws SQLException{
    String queryCheck = "SELECT * FROM Utente WHERE username = ? AND password = ?";
    PreparedStatement st = this.connection.prepareStatement(queryCheck); // <-- this generate exception
    st.setString(1, username);
    st.setString(2, password);
    ResultSet rs = st.executeQuery();
    return rs;
}

这一行是与数据库的第一次交互,所以我认为这个执行是 MySQL 数据库连接问题的后果。 我该如何解决这个问题?

这是 Azure 日志文件:

2017-06-24T16:02:47.7595782Z
2017-06-24T16:02:47.7752042Z w3wp, pid=8992, tid=6
2017-06-24T16:02:47.7752042Z "D:\Program Files (x86)\mysql\5.7.9.0\bin\mysqld.exe" --console --bind-address=127.0.0.1 --explicit_defaults_for_timestamp --basedir="D:\Program Files (x86)\mysql\5.7.9.0" --datadir="C:\DWASFiles\Sites\fishingassistant\VirtualDirectory0\data\mysql" --port="51477" --tmpdir="D:\local\temp\mysql" --innodb_temp_data_file_path="..\..\..\temp\mysql\ibtmp1:12M:autoextend" --pid-file="D:\local\temp\mysql\RD00155D4B30AE.pid" 
2017-06-24T16:02:47.8120705Z mysqld:5600 started
2017-06-24T16:02:48.072095Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2017-06-24T16:02:48.072095Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2017-06-24T16:02:48.072095Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2017-06-24T16:02:48.072095Z 0 [ERROR] Cannot open Windows EventLog; check privileges, or start server with --log_syslog=0
2017-06-24T16:02:48.072095Z 0 [Note] D:\Program Files (x86)\mysql\5.7.9.0\bin\mysqld.exe (mysqld 5.7.9) starting as process 5600 ...
2017-06-24T16:02:48.103333Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2017-06-24T16:02:48.103333Z 0 [Note] InnoDB: Uses event mutexes
2017-06-24T16:02:48.103333Z 0 [Note] InnoDB: Memory barrier is not used
2017-06-24T16:02:48.103333Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-06-24T16:02:48.103333Z 0 [Note] InnoDB: Number of pools: 1
2017-06-24T16:02:48.103333Z 0 [Note] InnoDB: Not using CPU crc32 instructions
2017-06-24T16:02:48.181459Z 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2017-06-24T16:02:48.228336Z 0 [Note] InnoDB: Completed initialization of buffer pool
2017-06-24T16:02:50.790850Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2017-06-24T16:02:55.587805Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2017-06-24T16:02:55.587805Z 0 [Note] InnoDB: Setting file '..\..\..\temp\mysql\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2017-06-24T16:02:55.603448Z 0 [Note] InnoDB: File '..\..\..\temp\mysql\ibtmp1' size is now 12 MB.
2017-06-24T16:02:55.603448Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2017-06-24T16:02:55.603448Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2017-06-24T16:02:55.603448Z 0 [Note] InnoDB: Waiting for purge to start
2017-06-24T16:02:55.665943Z 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 7437ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.)
2017-06-24T16:02:55.698474Z 0 [Note] InnoDB: 5.7.9 started; log sequence number 2644547
2017-06-24T16:02:55.714106Z 0 [Note] InnoDB: not started
2017-06-24T16:02:55.714106Z 0 [Note] Plugin 'FEDERATED' is disabled.
2017-06-24T16:02:55.714106Z 0 [Note] InnoDB: Loading buffer pool(s) from C:\DWASFiles\Sites\fishingassistant\VirtualDirectory0\data\mysql\ib_buffer_pool
2017-06-24T16:02:56.448492Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2017-06-24T16:02:56.448492Z 0 [Note] Server hostname (bind-address): '127.0.0.1'; port: 51477
2017-06-24T16:02:56.464119Z 0 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
2017-06-24T16:02:56.464119Z 0 [Note] Server socket created on IP: '127.0.0.1'.
2017-06-24T16:02:58.754886Z 0 [Note] Event Scheduler: Loaded 0 events
2017-06-24T16:02:58.754886Z 0 [Note] D:\Program Files (x86)\mysql\5.7.9.0\bin\mysqld.exe: ready for connections.
Version: '5.7.9'  socket: ''  port: 51477  MySQL Community Server (GPL)
2017-06-24T16:02:58.7548866Z mysqld(5600) is ready at port 51477!
2017-06-24T16:02:59.651433Z 0 [Note] InnoDB: Buffer pool(s) load completed at 170624 16:02:59
2017-06-24T16:13:01.451565Z 0 [Note] D:\Program Files (x86)\mysql\5.7.9.0\bin\mysqld.exe: Normal shutdown

2017-06-24T16:13:01.451565Z 0 [Note] Giving 0 client threads a chance to die gracefully
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down slave threads
2017-06-24T16:13:01.451565Z 0 [Note] Forcefully disconnecting 0 remaining clients
2017-06-24T16:13:01.451565Z 0 [Note] Event Scheduler: Purging the queue. 0 events
2017-06-24T16:13:01.451565Z 0 [Note] Binlog end
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'ngram'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'partition'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'BLACKHOLE'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'ARCHIVE'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'MyISAM'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_CMP'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'INNODB_TRX'
2017-06-24T16:13:01.451565Z 0 [Note] Shutting down plugin 'InnoDB'
2017-06-24T16:13:01.451565Z 0 [Note] InnoDB: FTS optimize thread exiting.
2017-06-24T16:13:01.451565Z 0 [Note] InnoDB: Starting shutdown...
2017-06-24T16:13:01.576497Z 0 [Note] InnoDB: Dumping buffer pool(s) to C:\DWASFiles\Sites\fishingassistant\VirtualDirectory0\data\mysql\ib_buffer_pool
2017-06-24T16:13:01.592121Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 170624 16:13:01
2017-06-24T16:13:03.522938Z 0 [Note] InnoDB: Shutdown completed; log sequence number 2644575
2017-06-24T16:13:03.522938Z 0 [Note] InnoDB: Removed temporary tablespace data file: "..\..\..\temp\mysql\ibtmp1"
2017-06-24T16:13:03.522938Z 0 [Note] Shutting down plugin 'MEMORY'
2017-06-24T16:13:03.522938Z 0 [Note] Shutting down plugin 'CSV'
2017-06-24T16:13:03.522938Z 0 [Note] Shutting down plugin 'sha256_password'
2017-06-24T16:13:03.522938Z 0 [Note] Shutting down plugin 'mysql_native_password'
2017-06-24T16:13:03.522938Z 0 [Note] Shutting down plugin 'binlog'
2017-06-24T16:13:03.522938Z 0 [Note] D:\Program Files (x86)\mysql\5.7.9.0\bin\mysqld.exe: Shutdown complete

更新: 如果我将上述 JDBC Mysql 连接参数更改为以下错误:

private final String urlDB = "jdbc:mysql://127.0.blabla:51477/localdb";

我得到了同样的例外……这太疯狂了……

【问题讨论】:

  • 嗨,Fobi,我也遇到了同样的错误,你能解决这个问题吗?
  • 不幸的是没有。如果你能解决它,你能给我解释一下吗?
  • 不,我还在寻找解决方案。
  • 请提供SELECT * FROM information_schema.INNODB_METRICS WHERE name LIKE 'buffer_%' ; -- 我看看能不能从那里得到一些线索。

标签: java mysql azure servlets azure-web-app-service


【解决方案1】:

你的数据库没有按照日志运行,所以你的代码在所有情况下都会抛出异常。

看线:

2017-06-24T16:02:48.072095Z 0 [ERROR] Cannot open Windows EventLog; check privileges, or start server with --log_syslog=0

按照指示更改您的 mysql 启动,您的代码可能会运行良好。

【讨论】:

  • 是的,但是如果我在 Azure 仪表板上看到“进程 exlporer”,我可以看到 mysqld 进程并且我知道这意味着 db 正在运行......那么我该如何运行它呢?跨度>
猜你喜欢
  • 1970-01-01
  • 2018-02-20
  • 1970-01-01
  • 1970-01-01
  • 2015-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-28
相关资源
最近更新 更多