简体   繁体   English

Azure上的Java Web应用程序+ MySQL应用程序内

[英]Java web app + mySQL in-app on Azure

I have tested locally a web app composed of servlets, html, js, css and a MySql database. 我已经在本地测试了一个由servlet,html,js,css和MySql数据库组成的Web应用程序。 It works perfectly, no error, no exeptions, nothing. 它运行完美,没有错误,没有异常,没有任何问题。

Now, throught my university I have the opportunity of a free test of the new MySQL in-app feature of Microsoft Azure and I have decided to put my web app on Azure using this new feature. 现在,在我的大学中,我有机会免费测试Microsoft Azure的MySQL新应用程序内功能,并且我决定使用此新功能将Web应用程序放到Azure上。

So, on Azure Dashbord I have choosed the "Web App + MySQL" option and, in the subsequential sub menu, the "MySQL in-app" option. 因此,在Azure Dashbord上,我选择了“ Web App + MySQL”选项,在随后的子菜单中选择了“ MySQL in-app”选项。

In my web app I use JDBC for connecting my Java servlets to Mysql database. 在我的Web应用程序中,我使用JDBC将Java servlet连接到Mysql数据库。 I Know that I must take the database connection parameters from the MYSQLCONNSTR_localdb environment variable. 我知道我必须从MYSQLCONNSTR_localdb环境变量中获取数据库连接参数。 I am able to take theese parametrs both from a java servlet ( with System.getenv("MYSQLCONNSTR_localdb") ), and via Kudu console (observing the file in data/mysql/MYSQLCONNSTR_localdb.txt). 我既可以从Java servlet(带有System.getenv(“ MYSQLCONNSTR_localdb”))中获取这些参数,也可以通过Kudu控制台(在data / mysql / MYSQLCONNSTR_localdb.txt中查看文件)获取这些参数。 In both cases i see tha same values and these are: 在两种情况下,我都看到相同的值,它们是:

Database=localdb;Data Source=127.0.0.1:51477;User Id=azure;Password=6#vWHD_$ 数据库=本地数据库;数据源= 127.0.0.1:51477;用户ID =天蓝色;密码= 6#vWHD_ $

I have use them with JDBC in my Java class: 我在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();
        }
    }
    ...

I am able to deploy my .war on Azure (in /site/wwwroot/webapps) via FileZilla FTP but with this URL: 我可以通过FileZilla FTP将我的.war部署在Azure上(在/ site / wwwroot / webapps中),但使用以下URL:

fishingassistant.azurewebsites.net/FishingAssistantWebApp/ fishingassistant.azurewebsites.net/FishingAssistantWebApp/

I can see the index of my web app (a login page) but when I click a button for sending username and password to the associated servlet, I obtain a "HTTP Status 500 -" like this: 我可以看到我的Web应用程序的索引(登录页面),但是当我单击用于向关联的Servlet发送用户名和密码的按钮时,将获得“ HTTP Status 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)

This exeption describe this line of code (line 181): 此示例描述了以下代码行(第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;
}

This line is the first interaction with the databese so I think that this execption is a conseguence of a MySQL database connection problem. 该行是与数据库之间的第一次交互,因此我认为此执行是MySQL数据库连接问题的必然结果。 How can I solve this? 我该如何解决?

This is the Azure log file: 这是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 

UPDATE: if I change the above JDBC Mysql Connection parameters with somethings of wrong like: 更新:如果我更改了上面的JDBC Mysql Connection参数时出现了一些错误,例如:

private final String urlDB = "jdbc:mysql://127.0.blabla:51477/localdb"; 私有最终字符串urlDB =“ jdbc:mysql://127.0.blabla:51477 / localdb”;

I obtain the same exception.... this is crazy... 我得到了同样的例外...。这太疯狂了...

Your database is not running according to the log, so your code will throw exceptions in all cases. 您的数据库未根据日志运行,因此您的代码在所有情况下都会引发异常。

Look at line: 看一下行:

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

Alter your boot up of mysql as indicated and your code might work nicely. 按照指示更改mysql的启动,您的代码可能会正常工作。

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

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