mysql update error for below queries - mysql

I am using follwing query to update.
my update function and connection string is in jar file.
I am using JSP useBean to call function from jar file.
I am able to run select queries on databse.
only getting problem in updating .
why I am getting this error now earlier it was working fine.
queries
String sql="INSERT INTO tm_visitor(VDT,VID,VISITOR_TEXT,COMPANY_TEXT,CONTACT,PERSON_TO_MEET,DEPARTMENT_TEXT,FLOOR)SELECT REPLACE(LEFT(NOW(), 10), '-', ''), LPAD(COALESCE(MAX(VID) + 1, 000001),6,'0'),?,?,?,?,?,? FROM tm_visitor";
query2
String sql2="INSERT INTO tm_belonging(BID,BELONGING_TYPE,BELONGING_TEXT)VALUES(LAST_INSERT_ID(),?,?)";
error:
Error in DBConnect com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Y
ou have an error in your SQL syntax; check the manual that corresponds to your M
ySQL server version for the right syntax to use near '?,?,?,?,?,? FROM tm_visito
r' at line 1
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in
your SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near '?,?,?,?,?,? FROM tm_visitor' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3536)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3468)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1957)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2642)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1634)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1553)
at com.vms.util.MyDBConnect.exeUpdate(Unknown Source)
at org.apache.jsp.applicationservices.fileshare.vm.apps.admin.visitorSub
mit_jsp._jspService(visitorSubmit_jsp.java:148)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
13)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:48
9)
at java.lang.Thread.run(Unknown Source)
Error in DBConnect com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Y
ou have an error in your SQL syntax; check the manual that corresponds to your M
ySQL server version for the right syntax to use near '?,?)' at line 1
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in
your SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near '?,?)' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3536)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3468)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1957)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2642)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1634)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1553)
at com.vms.util.MyDBConnect.exeUpdate(Unknown Source)
at org.apache.jsp.applicationservices.fileshare.vm.apps.admin.visitorSub
mit_jsp._jspService(visitorSubmit_jsp.java:151)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
13)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:48
9)
at java.lang.Thread.run(Unknown Source)
EDIT
JSP CODE:
<jsp:useBean id="mdc" class="com.vms.util.MyDBConnect"/>
boolean status=false;
String VisitorName="",Company="",Contact="",WhomeToMeet="",Department="",DepartmentFloor="";
String Belonging="",BType="",Belonging2="",BType2="",Belonging3="",BType3="";
String Btype="",Belong="";
try
{
VisitorName=(String)request.getParameter("VisitorName");
out.println(","+VisitorName);
Company=(String)request.getParameter("Company");
out.println(","+Company);
Contact=(String)request.getParameter("Contact");
out.println(","+Contact);
WhomeToMeet=(String)request.getParameter("WhomeToMeet");
out.println(","+WhomeToMeet);
Department=(String)request.getParameter("Department");
out.println(","+Department);
DepartmentFloor=(String)request.getParameter("DepartmentFloor");
out.println(","+DepartmentFloor);
BType=(String)request.getParameter("BType0");
out.println(","+BType);
Belonging=(String)request.getParameter("Belonging0");
out.println(","+Belonging);
String sql="INSERT INTO tm_visitor(VDT,VID,VISITOR_TEXT,COMPANY_TEXT,CONTACT,PERSON_TO_MEET,DEPARTMENT_TEXT,FLOOR)SELECT REPLACE(LEFT(NOW(), 10), '-', ''), LPAD(COALESCE(MAX(VID) + 1, 000001),6,'0'),?,?,?,?,?,? FROM tm_visitor";
//System.out.println(sql);
String sql2="INSERT INTO tm_belonging(BID,BELONGING_TYPE,BELONGING_TEXT)VALUES(LAST_INSERT_ID(),?,?)";
//System.out.println(sql2);
mdc.exeUpdate(sql);
mdc.exeUpdate(sql2);
}
catch(Exception e)
{
e.printStackTrace();
//System.out.println("eRROR>>\n"+e);
}

Whenever yo use an ? in your statement, means that it will be "replaced" by a parameter.
You have to bind those paramters when executing the query.
Using standard JDBC syntax, it will be something like :
PreparedStatement prepStmt = connection.prepareStatement(sql);
prepStmt.setString(1, paramValue1);
prepStmt.setInt(2, paramValue2);
....
prepStmt.setInt(n, paramValueN);
prepStmt.execute();
Hope it helps

Related

Pentaho server init with MySQLSyntaxErrorException

I have a fresh install of Pentaho Server CE 9.3.0.0-428 with MySql 8.028 and connector 8.0.29.
When it's starting it throws many MySQLSyntaxErrorException. It seems a create table statement, which is really wrong: FSENTRY_NAME varchar not null (missing the size of varchar type from column definition).
I tried with MySql 5.7.38 and connector 5.1.17 (included in Pentaho bundle) too, without any success.
Here is a log detail
2022-07-21 15:49:54,826 ERROR [org.apache.jackrabbit.core.fs.db.DatabaseFileSystem] failed to initialize file system
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'not null, FSENTRY_NAME varchar not null, FSENTRY_DATA varbinary null, FSENTRY_LA' at line 1
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]
at java.lang.reflect.Constructor.newInstance(Constructor.java:481) ~[?:?]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[mysql-connector-java-5.1.17.jar:?]
at com.mysql.jdbc.Util.getInstance(Util.java:386) ~[mysql-connector-java-5.1.17.jar:?]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052) ~[mysql-connector-java-5.1.17.jar:?]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597) ~[mysql-connector-java-5.1.17.jar:?]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529) ~[mysql-connector-java-5.1.17.jar:?]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990) ~[mysql-connector-java-5.1.17.jar:?]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151) ~[mysql-connector-java-5.1.17.jar:?]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619) ~[mysql-connector-java-5.1.17.jar:?]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2569) ~[mysql-connector-java-5.1.17.jar:?]
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:824) ~[mysql-connector-java-5.1.17.jar:?]
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:667) ~[mysql-connector-java-5.1.17.jar:?]
at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264) ~[commons-dbcp-1.4.jar:1.4]
at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264) ~[commons-dbcp-1.4.jar:1.4]
at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264) ~[commons-dbcp-1.4.jar:1.4]
at org.apache.jackrabbit.core.util.db.ConnectionHelper.reallyExec(ConnectionHelper.java:308) ~[jackrabbit-data-2.16.5.jar:2.16.5]
at org.apache.jackrabbit.core.util.db.ConnectionHelper$1.call(ConnectionHelper.java:293) ~[jackrabbit-data-2.16.5.jar:2.16.5]
at org.apache.jackrabbit.core.util.db.ConnectionHelper$1.call(ConnectionHelper.java:289) ~[jackrabbit-data-2.16.5.jar:2.16.5]
at org.apache.jackrabbit.core.util.db.ConnectionHelper$RetryManager.doTry(ConnectionHelper.java:544) ~[jackrabbit-data-2.16.5.jar:2.16.5]
at org.apache.jackrabbit.core.util.db.ConnectionHelper.exec(ConnectionHelper.java:297) ~[jackrabbit-data-2.16.5.jar:2.16.5]
at org.apache.jackrabbit.core.util.db.CheckSchemaOperation.run(CheckSchemaOperation.java:89) ~[jackrabbit-data-2.16.5.jar:2.16.5]
at org.apache.jackrabbit.core.fs.db.DatabaseFileSystem.init(DatabaseFileSystem.java:193) ~[jackrabbit-core-2.16.5.jar:2.16.5]
at org.apache.jackrabbit.core.config.RepositoryConfigurationParser$6.getFileSystem(RepositoryConfigurationParser.java:1164) ~[jackrabbit-core-2.16.5.jar:2.16.5]
at org.apache.jackrabbit.core.config.RepositoryConfig.getFileSystem(RepositoryConfig.java:926) ~[jackrabbit-core-2.16.5.jar:2.16.5]
at org.apache.jackrabbit.core.RepositoryImpl.<init>(RepositoryImpl.java:265) ~[jackrabbit-core-2.16.5.jar:2.16.5]
at org.apache.jackrabbit.core.RepositoryImpl.create(RepositoryImpl.java:616) ~[jackrabbit-core-2.16.5.jar:2.16.5]
at org.springframework.extensions.jcr.jackrabbit.RepositoryFactoryBean.createRepository(RepositoryFactoryBean.java:68) ~[se-jcr-0.9.jar:?]
at org.springframework.extensions.jcr.RepositoryFactoryBean.afterPropertiesSet(RepositoryFactoryBean.java:61) ~[se-jcr-0.9.jar:?]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1847) ~[spring-beans-5.3.3.jar:5.3.3]

Wildfly 9.1 smtp mail substem - Couldn't connect to host, port: localhost, 25; timeout -1;

I'm working with wildfly as for a while and I cant get its mail subsystem working. I have seen many tutorials how to set it up whether through web console, CLI or directly in standalone.xml so I'm pretty sure that my config is right:
<subsystem xmlns="urn:jboss:domain:mail:2.0">
<mail-session debug="true" name="Gmail" jndi-name="java:jboss/mail/Gmail" from="MAILFROM">
<smtp-server outbound-socket-binding-ref="mail-smtp" ssl="true" username="MAILFROM" password="PASSWORD"/>
</mail-session>
</subsystem>
<outbound-socket-binding name="mail-smtp">
<remote-destination host="smtp.gmail.com" port="465"/>
</outbound-socket-binding>
And then in my Java file:
#Resource(mappedName = "java:jboss/mail/Gmail")
private javax.mail.Session gmailSession;
public void sendEmail(String to,String subject,String msg){
Message message = new MimeMessage(gmailSession);
message.setFrom(newInternetAddress("MAILFROM"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
message.setSubject(subject);
message.setContent(msg,"text/html");
Transport.send(message);}
And I get:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2054)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)
at javax.mail.Service.connect(Service.java:364)
at javax.mail.Service.connect(Service.java:245)
at javax.mail.Service.connect(Service.java:194)
at javax.mail.Transport.send0(Transport.java:253)
at javax.mail.Transport.send(Transport.java:124)
at com.liferoles.controller.UserManager.sendEmail(UserManager.java:487)
at com.liferoles.controller.UserManager.sendResetLink(UserManager.java:520)
at com.liferoles.rest.RestAuth.sendResetLink(RestAuth.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:329)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2020)
... 52 more
The weird thing is that it works with same properties when using javax.mail API directly like this:
public void sendEmail(String to,String subject,String msg){
Properties properties = System.getProperties();
String user = "MAILFROM";
String passwd = "PASSWORD";
properties.setProperty("mail.smtp.auth", "true");
properties.setProperty("mail.smtp.starttls.enable", "true");
properties.setProperty("mail.smtp.host", "smtp.gmail.com");
properties.setProperty("mail.smtp.port", "587");
javax.mail.Session gmailSession = javax.mail.Session.getInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, passwd);
}
});
Message message = new MimeMessage(gmailSession);
message.setFrom(new InternetAddress("MAILFROM"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
message.setSubject(subject);
message.setContent(msg,"text/html");
Transport.send(message);
I'm trying to solve this issue for two reasons:
I want to have my credentials in standalone.xml not in my java class.
And mainly because I hate when something is weird and i cant get it working!
The second thing i do not understand clearly is why am I getting this exception:
15:25:28,587 ERROR [stderr] (default task-10)javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorExc
eption: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid cert
ification path to requested target
15:25:28,587 ERROR [stderr] (default task-10) at com.liferoles.controller.UserManager.sendEmail(UserManager.java:484)
15:25:28,587 ERROR [stderr] (default task-10) at com.liferoles.controller.UserManager.sendResetLink(UserManager.java:5
14)
15:25:28,587 ERROR [stderr] (default task-10) ... 44 more
15:25:28,588 ERROR [stderr] (default task-10) Caused by: javax.mail.MessagingException: Could not convert socket to TLS;
15:25:28,588 ERROR [stderr] (default task-10) nested exception is:
15:25:28,588 ERROR [stderr] (default task-10) javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorExc
eption: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid cert
ification path to requested target
15:25:28,588 ERROR [stderr] (default task-10) at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:2000)
15:25:28,588 ERROR [stderr] (default task-10) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:70
9)
15:25:28,588 ERROR [stderr] (default task-10) at javax.mail.Service.connect(Service.java:386)
15:25:28,589 ERROR [stderr] (default task-10) at javax.mail.Service.connect(Service.java:245)
15:25:28,589 ERROR [stderr] (default task-10) at javax.mail.Service.connect(Service.java:194)
15:25:28,589 ERROR [stderr] (default task-10) at javax.mail.Transport.send0(Transport.java:253)
15:25:28,589 ERROR [stderr] (default task-10) at javax.mail.Transport.send(Transport.java:124)
15:25:28,589 ERROR [stderr] (default task-10) at com.liferoles.controller.UserManager.sendEmail(UserManager.java:481)
15:25:28,590 ERROR [stderr] (default task-10) ... 45 more
15:25:28,590 ERROR [stderr] (default task-10) Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.Val
idatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find v
alid certification path to requested target
when trying to send email by the second method I mentioned. This error only occurs in case that I am running starting my wildfly server from console with standalone.bat command.. If I am runing it through eclipse "run on server" it works. Confused for a second time. I tried to solve this second problem by adding my selfsigned certificate to jdks cacerts but it didn't help.
What kind of class is your Java code with #Resource in? Most likely the resource is not being injected because your code is not in a managed bean/class of some sort. Check whether gmailSession is non-null to make sure the injection is working.
The cert path error is definitely a problem with certificates in your trust store. Normally the Gmail certificate should validate with the default trust store. Perhaps you have an anti-virus product that's intercepting the request? Did you check the JavaMail FAQ entry?

MariaDB CommunicationsException: Communications link failure

There seems to be enough of questions relating to CommunicationsException were posted on Stackoverflow. But none of them helps me out of a difficult position.
I installed MariaDB 5.5 in my CentOS 7 server, and configured everything so that I can connect to the DB server remotely through a MySQL Workbench or Data Source Explorer in eclipse. A screen capture of the succeed connections is like below.
However, when I try to connect the DB Server via JDBC, it continues to fail with the Exception "com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure".
The test class is shown as following.
package com.pratice;
import java.sql.*;
public class DatabaseConn {
public static void main(String[] args) throws Exception{
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
String url = "jdbc:mysql://59.12.140.121:6330/myPrjs";//?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true
String username = "user";
String password = "password";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
conn = DriverManager.getConnection(url, username, password);
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT 1");
while(rs.next()){
System.out.print(rs.getObject(1) + "\t" + rs.getObject(2));
}
}finally{
if(rs!=null) {
rs.close();
}
if(stmt!=null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
}
}
}
When I run DatabaseConn, I got the error messages.
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1127)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:356)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2502)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2539)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2321)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at com.webjsp.pratice.DatabaseConn.main(DatabaseConn.java:18)
Caused by: java.net.SocketException: Bad address: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:241)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:258)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:306)
... 15 more
I cannot solve this problem so I searched on the internet, and I found a checklist at here . But now that I can connect to my DB server via IDEs, I don't know what could be wrong.
I also tried to use org.mariadb.jdbc.driver instead of mysql driver, I got error messages too.
Exception in thread "main" java.sql.SQLNonTransientConnectionException: Could not connect to 59.12.140.121:6330 : Bad address: connect
at org.mariadb.jdbc.internal.SQLExceptionMapper.get(SQLExceptionMapper.java:136)
at org.mariadb.jdbc.internal.SQLExceptionMapper.throwException(SQLExceptionMapper.java:106)
at org.mariadb.jdbc.Driver.connect(Driver.java:115)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DatabaseConn.main(DatabaseConn.java:16)
Caused by: org.mariadb.jdbc.internal.common.QueryException: Could not connect to 59.12.140.121:6330
: Bad address: connect
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:714)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.<init>(MySQLProtocol.java:280)
at org.mariadb.jdbc.Driver.connect(Driver.java:111)
... 3 more
Caused by: java.net.SocketException: Bad address: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:387)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:709)
... 5 more
Could anyone tell me how can I solve this problem, or give me some hints that why does it happening? Thank you so much.
The key point to figure the problem out is at "java.net.SocketException: Bad address: connect".
The problem was caused by firewall rules at the client side (My Windows PC). I enabled Ahnlab V3 Internet Security Personal Firewall on my client PC. The outbound rules only allow certain types of outgoing socket by default. When I tried to connect to my remote server with a workbench, there was no problem. But when I tried to connect to the server by running the java Class, the local firewall kept the socket, so the connection requests did not even go through my network card! I add a new outbound rule which allows mysql outbound connection, and then my program runs normally.
Hope this will help anyone who encounters the same problem.

Exception while dropping database in JavaFX

private void delete() throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager
.getConnection("jdbc:mysql://localhost:3306/delete?"
+ "user=root&password=virus");
statement = connect.createStatement();
preparedStatement = connect
.prepareStatement("DROP DATABASE delete");
preparedStatement.executeUpdate();
preparedStatement = connect
.prepareStatement("CREATE DATABASE delete");
preparedStatement.executeUpdate();
}
This is my code to delete a database in javafx. But when i ran this code it gives me an exception. Is details are -
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delete' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2794)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at deleteaccount.DeleteAccount.delete(DeleteAccount.java:106)
at deleteaccount.DeleteAccount.access$000(DeleteAccount.java:26)
at deleteaccount.DeleteAccount$1.handle(DeleteAccount.java:86)
at deleteaccount.DeleteAccount$1.handle(DeleteAccount.java:82)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
Why this exception occur ? How can I solve it ?

getting an error after executing registration form in jsp

I am trying to execute the registercase.jsp page which is having some form detail after submitting these detail towards insert.jsp getting an below error in tomcat logs.please help me if possible.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
to use near ') values('null','null','null',null)' at line 1com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that c
orresponds to your MySQL server version for the right syntax to use near ') values('null','null','null',null)' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2788)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1816)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1730)
at org.apache.jsp.insert_jsp._jspService(insert_jsp.java:75)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Query -
int i=st.executeUpdate ("insert into issue_creating(issue_id,case_title,Problem_Submit,Problem_De‌​scr,) values('"+Issue_ID+"','"+Case_Title+"','"+Problem_Submit+"',‌​'"+Problem_Descr+"')‌​");
You should organize query in well formed insert sentence.
there should not be any extra comma(,) here - Problem_De‌​scr,
It should be -
int i=st.executeUpdate (
"insert into issue_creating(issue_id,case_title,Problem_Submit,Problem_De‌​
scr) values('"+Issue_ID+"','"+Case_Title+"','"+Problem_Submit+"',‌​
'"+Problem_Descr+"')‌​");
Kindly use PreparedStatement in future to avoid such issues.
I hope this will help.