tangara goh wrote:I can get a ping successfully to MYSQL 8
tangara goh wrote:but when I run my webApp, the console will say ERROR: Unable to Connect to Database.
Ron McLeod wrote:
tangara goh wrote:I can get a ping successfully to MYSQL 8
How did you do that?
Using Data Explorer in Eclipse where you input all the connections parameters.
tangara goh wrote:but when I run my webApp, the console will say ERROR: Unable to Connect to Database.
Where is that message coming from?
The message is printed to console I think it is from TOMCAT
How are you connecting to the database - using a DataSource or the DriverManager?
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:Don't use DriverManager in a webapp. It's crude and inefficient. Use a DataSource:
https://www.journaldev.com/2513/tomcat-datasource-jndi-example-java
If you use a DataSource, it becomes Tomcat's job to ensure connection to the database and Tomcat has very good diagnostics.
23:05:48.732 [http-nio-8013-exec-2] ERROR daoMySql.tutorDAOImpl - Failed to obtain JDBC connection
java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';autoReconnect=true&useSSL=false; &logger=com.mysql.cj.jdbc.log.Slf4JLogger&profileSQL=true'.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) ~[mysql-connector-java-8.0.12.jar:8.0.12]
Ron McLeod wrote:This looks suspicious:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/K/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.11.1/log4j-slf4j-impl-2.11.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/K/.m2/repository/org/slf4j/slf4j-nop/1.7.25/slf4j-nop-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
[Fatal Error] :17:116: The reference to entity "useSSL" must end with the ';' delimiter.
ERROR StatusLogger Error parsing C:\Users\K\eclipse-workspace\webApp5\target\classes\log4j2.xml org.xml.sax.SAXParseException; lineNumber: 17; columnNumber: 116; The reference to entity "useSSL" must end with the ';' delimiter.
<param name="URL" value="jdbc:mysql://localhost/project?serverTimezone=UTC&autoReconnect=true&useSSL=False;"/>
tangara goh's log wrote:
[Fatal Error] :17:116: The reference to entity "useSSL" must end with the ';' delimiter.
ERROR StatusLogger Error parsing C:\Users\K\eclipse-workspace\webApp5\target\classes\log4j2.xml org.xml.sax.SAXParseException; lineNumber: 17; columnNumber: 116; The reference to entity "useSSL" must end with the ';' delimiter.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
tangara goh wrote:I corrected but now I kept getting this error and no matter what I do, it still continues giving me this error message :
And here's my modified String URL :
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:I think I see.
You're being nuked by XML, it appears.
Try this syntax, instead:
The ampersand is one of the 5 "magic characters" in XML. It indicates that everything up to a terminating ";" should be considered as a name or value of an XML entity.
Except that the XML parser doesn't see the ';' before it sees the "=" and it chokes. Using the "&" entity name escapes that behaviour.
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration debug="false" <br /> xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- APPENDERS LIST -->
<!-- show log entries on console -->
<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} [%-5p][%-16.16t][%32.32c] - %m%n" />
<param name="Threshold" value="info"/>
</layout>
</appender>
<appender name="ConsoleAppender" class="org.apache.log4j.jdbc.JDBCAppender">
<param name="URL" value="jdbc:mysql://localhost/project?serverTimezone=UTC&autoReconnect=true&useSSL=False;"/>
<param name="driver" value="com.mysql.cj.jdbc.Driver" />
<param name="user" value="user" />
<param name="password" value="password" />
<Column name="LOGGER" pattern="%C" />
<Column name="Level" pattern="%level" />
<Column name="Message" pattern="%m" />
<Column name="UserName" pattern="%x" />
<Column name="Priority" pattern="%p" />
<param name="sql" <br /> value="INSERT INTO logs(user_id, dated,logger,lev,message) VALUES('%t', '%d{yyyy-MM-dd HH:mm:ss}','%-50c{3}','%p','%m')" />
</appender>
<root>
<priority value="ERROR" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4j:configuration>
Dave Tolls wrote:That's different from the original error, so what does your connection string look like now?
Dave Tolls wrote:Well, that one doesn't seem to match the error posted earlier.
Are you sure that ULR caused that error?
All things are lawful, but not all things are profitable.
tangara goh wrote:Hi Dave,
Basically, all my connection URL are static and I stored them in a singleton class.
So, I just use the tutorImpl to get the connection from there.
And the error points out that it comes from that URL string....
All things are lawful, but not all things are profitable.
Knute Snortum wrote:Change all the & to &
Knute Snortum wrote:The &s have turned back into just &.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:
Knute Snortum wrote:The &s have turned back into just &.
Note for the confused: The JavaRanch message display system also evaluates the '&' entity, so make sure when you type or copy an example to preview the output. If it's getting mangled, use the escapes to make it display as you are actually seeing it on your machine.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:Do you really mean "amp&" and not "&"?
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |