integrating apache tomcat and solr - java

I am trying to integrate apache tomcat (version 7)and solr (version 4) and i am getting this error :
HTTP Status 500 - {msg=SolrCore 'collection1' is not available due to init failure:
The filename, directory name, or volume label syntax is incorrect,
trace=org.apache.solr.common.SolrException: SolrCore 'collection1' is not available due to init failure: The filename, directory name, or volume label syntax is incorrect at
org.apache.solr.core.CoreContainer.getCore(CoreContainer.java:1212) at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:248) at
org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:155) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442) at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082) at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623) at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at
java.lang.Thread.run(Unknown Source) Caused by:
org.apache.solr.common.SolrException: The filename, directory name, or volume label syntax is incorrect at
org.apache.solr.core.SolrCore.<init>(SolrCore.java:821) at
org.apache.solr.core.SolrCore.<init>(SolrCore.java:618) at
org.apache.solr.core.CoreContainer.createFromLocal(CoreContainer.java:949) at
org.apache.solr.core.CoreContainer.create(CoreContainer.java:984) at
org.apache.solr.core.CoreContainer$2.call(CoreContainer.java:597) at
org.apache.solr.core.CoreContainer$2.call(CoreContainer.java:592) at
java.util.concurrent.FutureTask.run(Unknown Source) at
java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at
java.util.concurrent.FutureTask.run(Unknown Source) at
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor
$Worker.run(Unknown Source) ... 1 more
Caused by: java.io.IOException: The filename, directory name, or volume label syntax is incorrect at
java.io.WinNTFileSystem.canonicalize0(Native Method) at java.io.Win32FileSystem.canonicalize(Unknown Source)
at java.io.File.getCanonicalPath(Unknown Source) at
org.apache.solr.core.StandardDirectoryFactory.normalize(StandardDirectoryFactory.java:47)
at org.apache.solr.core.SolrCore.initIndex(SolrCore.java:462) at
org.apache.solr.core.SolrCore.<init>(SolrCore.java:745) ... 11 more ,code=500}
please help me fix it!

Go to Solrconfig.xml and there will be a tag called as data directory , so just try to hard code the required path , if it works , then you can conclude that it is the root cause of the issue .

You can add the following java environment variable in tomcat startup configuration (in JAVA_OPTS for example).
-Dsolr.solr.home=<your solr.xml path>

Related

JDBC Realm authentication - ClassNotFoundException: com.mysql.jdbc.Driver

I know this is a duplicate question, but none of the other 15+ thread's answers helped, or i missed something.
I am trying to implement authentication using JDBC Realm in my JAX-WS java web app, and i can't even get past connecting to the db.
This is what i tried:
Adding the connector to the WEB-INF/lib dir in the app structure
Adding it to the build path
Adding it to the $CATALINA-HOME/lib of the server
Adding JRE, JDK, CATALINA_HOME paths to startap.bat
Cleaning the project
Deleting the contents of the temp folder
Enviromental variables:
User
System
Using:
apache-tomee-plus-1.7.4
jre1.8.0_161
jdk1.8.0_144
Actual trace:
Apr 13, 2018 9:07:49 PM org.apache.catalina.realm.JDBCRealm getPassword
SEVERE: Exception performing authentication
java.sql.SQLException: com.mysql.jdbc.Driver
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:692)
at org.apache.catalina.realm.JDBCRealm.getPassword(JDBCRealm.java:544)
at org.apache.catalina.realm.RealmBase.getDigest(RealmBase.java:1266)
at org.apache.catalina.realm.RealmBase.authenticate(RealmBase.java:420)
at org.apache.catalina.realm.CombinedRealm.authenticate(CombinedRealm.java:111)
at org.apache.tomee.catalina.TomEERealm.authenticate(TomEERealm.java:55)
at org.apache.catalina.authenticator.DigestAuthenticator$DigestInfo.authenticate(DigestAuthenticator.java:708)
at org.apache.catalina.authenticator.DigestAuthenticator.authenticate(DigestAuthenticator.java:275)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:577)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:688)
... 20 more
As ashamed as i am, I have to admit that i used a wrong version of tomEE i had on my PC, that wasn't even connected to eclipse, but i was sure it was the right one, until i checked the actual path from eclipse.
Anyway, as JDBC Realm goes, as many other threads' answers suggested, the DBMS connector .jar needs to be in the servers lib directory ($CATALINA-HOME/lib).

java.lang.NoClassDefFoundError: org/apache/axiom/om/OMNode

Im having error its says java.lang.NoClassDefFoundError: org/apache/axiom/om/OMNode
in my java web application. By the way im implementing the servlet to call the dataservice in wso2 data service.
Here's the full stack trace:
type Exception report
message Error instantiating servlet class org.wso2.sample.RegisterpatientServlet
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Error instantiating servlet class org.wso2.sample.RegisterpatientServlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.NoClassDefFoundError: org/apache/axiom/om/OMNode
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
java.lang.Class.getConstructor0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.ClassNotFoundException: org.apache.axiom.om.OMNode
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1891)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1734)
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
java.lang.Class.getConstructor0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
Thank You Please Help! Im having hard time in this..
An easy way to make this class available to your web application is to put the axiom.jar file in your WEB-INF/lib folder.
The apache axiom library is not in your classpath. If you use maven, make sure that it is in your pom.xml. if it's there, make sure that it has the runtime scope: <scope>runtime</scope>.
Add below dependency to your project. (Change version as you want)
https://mvnrepository.com/artifact/org.apache.ws.commons.axiom/axiom-impl/1.2.6

JDBC - phpMyAdmin MySQL Can't login to database?

I'm hosting a web application through OpenShift. I added a MySQL database and created it with phpMyAdmin. Now, I think my server name is the name it shows on the phpMyAdmin page (127.01.201.302 for example). Now, I created a user 'localhostOnly' with the same password, I set the host to 'localhost' and priviliges to the insert, select update and delete.
But when i try to connect to it with the:
jdbc:mysql://127.01.201.302:3306/DB_NAME and using those login credentials, it gives this error:
java.sql.SQLException: Access denied for user 'localhostOnly'#'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3835)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3771)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:870)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1659)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1206)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2239)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2270)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2069)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at database.OpeningsTijdenDAO.selectTijden(OpeningsTijdenDAO.java:15)
at database.OTService.getTijden(OTService.java:13)
at servlets.GetTijdenServlet.doPost(GetTijdenServlet.java:17)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
NOTE: I am absolutely sure the login credentials are correct. I do not have XAMMP or something installed.
at java.lang.Thread.run(Unknown Source)
By having a look at the last line of the entire error-trace. I can assume that your program failed to locate your server by given URL. I think you might be missing port number for your MySQL server. If you haven't changed your port number, then it's most likely 3307 by default. Change your Database Source URL from
jdbc:mysql://127.01.201.302/DB_NAME
to
jdbc:mysql://127.01.201.302:3307/DB_NAME

ClassNotFoundException: javax.ws.rs.client.ClientBuilder

I´m trying to consume a Jersey Rest Service from a Web Application (Dynamic Web App in eclispe) as follows:
Client client = ClientBuilder.newBuilder().build(); // Here is the error
WebTarget target = client.target("url/rest").path("List");
String result = target.request(MediaType.TEXT_PLAIN).get(String.class);
When debugging in the line ClientBuilder.newBuilder() the system throws the ClassNotFoundException: javax.ws.rs.client.ClientBuilder error, but the same code, in a java project works perfect.
Full trace:
javax.servlet.ServletException: Error instanciando clase de servlet test
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
causa raíz
java.lang.NoClassDefFoundError: javax/ws/rs/client/ClientBuilder
test.<init>(test.java:27)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
causa raíz
java.lang.ClassNotFoundException: javax.ws.rs.client.ClientBuilder
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1324)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1177)
test.<init>(test.java:27)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
So here it comes ;)
First for the understanding:
javax.ws.rs.client is the standard package for RESTFul client implementations. Developers should programm against this interface.
At runtime you need an implementation of this interface in your classpath. Thats where projects like resteasy or jersey comes in.
Second:
In eclipse the buildpath and classpath settings only efect the environment in eclipse. When you put something in there manualy, it exist only in eclipse.
Third:
When you developing a webapplication depending on the Java EE webprofile you have automaticly access to all bundled packages of your application server like tomcat or jboss.
If your application uses more packages you have to distribute them together with your application. To do this you can place your third party jars under "WEB-INF/libs" in your project. When it is deployed to your application server, jars inside this folder are automaticly placed in your classpath of your app.
Fourth (about your solution):
Putting third party libs in the application server lib or endorsed directy make them accessable to all applications deployed on this application server and adds more complexity into your app server setup and maintenance.

J2EE connect remote Oracle DB table

I am using Windows 7, 64 bit and using Eclipse for J2EE. I want to display the values from Oracle database through J2EE code. I tried with oracle tutorial. But I am getting the below error in Eclipse console. Please suggest me.
additional details:
1. In remote oracle settings, I could see the Service-Name enabled, but not SID enabled.
2. My service name is 'sample.lan' and ofcourse I am working inside lan. whether I need to make any changes If I am connecting remote oracleDB table through LAN?
Connection string:
<%# page import="java.sql.*" %>
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection("jdbc:oracle:thin:#host:1521:service-name", "username", "password");
Error:
Connection Failed! Check output console
java.sql.SQLRecoverableException: I/O-Error: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:673)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:711)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:558)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.apache.jsp.testDBconnection_jsp._jspService(testDBconnection_jsp.java:94)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
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:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
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: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:445)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:464)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:594)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:229)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
... 32 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(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 oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:162)
at oracle.net.nt.ConnOption.connect(ConnOption.java:133)
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:411)
... 37 more
Make sure that you can reach port 1521 of your database host from wherever you are executing your java code.
Make sure too that you can connect to your database with some standard database client (SQL*plus for example) in order to check if your database is configured right
Check your connection URL to make sure if it is right (docs on that here http://www.orafaq.com/wiki/JDBC)
Besides that, just a remark: if your idea is to educate yourself or learn JDBC, this is perfectly right; if your code is intended for production, I strongly advise you against mixing database access into your presentantion layer (JSP). I suggest you consider in that case to split your application in layers defined by its responsability. http://en.wikipedia.org/wiki/Multitier_architecture

Categories