intellij idea hibernate - java.sql.SQLException: No database selected - intellij-idea

i'm having trubble in executing an SQL command with in intellij idea with hibernate.
this is the code i wrote:
import models.Employee;
import org.hibernate.ejb.HibernatePersistence;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.spi.PersistenceProvider;
import java.util.HashMap;
import java.util.List;
public class manager {
public final static String SELECT_QUERY = new String("from Employee where id =:id");
public static void main(String[] args){
int id = 21577911;
PersistenceProvider pp = new HibernatePersistence();
EntityManagerFactory emf = pp.createEntityManagerFactory("NewPersistenceUnit", new HashMap());
EntityManager em = emf.createEntityManager();
List<Employee> employees = em.createQuery(SELECT_QUERY, Employee.class).setParameter("id", id).getResultList();
System.out.println(employees);
em.close();
}
}
and these are the errors:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:273)
at manager.main(manager.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:61)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2036)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1836)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1815)
at org.hibernate.loader.Loader.doQuery(Loader.java:899)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
at org.hibernate.loader.Loader.doList(Loader.java:2522)
at org.hibernate.loader.Loader.doList(Loader.java:2508)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2338)
at org.hibernate.loader.Loader.list(Loader.java:2333)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:490)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1269)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:264)
... 6 more
Caused by: java.sql.SQLException: **No database selected**
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:56)
... 21 more
i have configured the persistence.xml exactly as in the video demo in:
http://www.jetbrains.com/idea/features/jpa_hibernate.html

Apparently this occurs when your application does not know what database to use. to resolve this issue, you should change your database driver url from:
"URL"="jdbc:mysql://localhost:3306/"
to
"URL"="jdbc:mysql://localhost:3306/databasename"

I am using hibernate in EJBs
and exception occurred in glassfish
SQL Error: 1046, SQLState: 3D000
No database selected
i did checked in glassfish JDBC connection pool additional propteries
URL and url property was set like this
jdbc:mysql://localhost:3306/
fix is just added database name in url and URL property
jdbc:mysql://localhost:3306/{databasename}
and it worked f
error was

Related

Intelij idea exported Java Jar file doesnt work properly java.security.NoSuchAlgorithmException

Hello Everyone!!
I am developing a server app in java lang in intelij idea it works properly
but when exporting as .jar file it gives an error like this
java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
at java.base/javax.net.ssl.DefaultSSLServerSocketFactory.throwException(SSLServerSocketFactory.java:177)
at java.base/javax.net.ssl.DefaultSSLServerSocketFactory.createServerSocket(SSLServerSocketFactory.java:190)
at com.company.ProxyServer.listen(ProxyServer.java:24)
at com.company.ProxyServer.run(ProxyServer.java:18)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
at java.base/java.security.Provider$Service.newInstance(Provider.java:1917)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
at java.base/javax.net.ssl.SSLContext.getInstance(SSLContext.java:185)
at java.base/javax.net.ssl.SSLContext.getDefault(SSLContext.java:110)
at java.base/javax.net.ssl.SSLServerSocketFactory.getDefault(SSLServerSocketFactory.java:74)
... 3 more
Caused by: java.security.KeyManagementException
at java.base/sun.security.ssl.SSLContextImpl$DefaultManagersHolder.<clinit>(SSLContextImpl.java:942)
at java.base/sun.security.ssl.SSLContextImpl$DefaultSSLContext.<init>(SSLContextImpl.java:1111)
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483)
at java.base/java.security.Provider$Service.newInstanceOf(Provider.java:1928)
at java.base/java.security.Provider$Service.newInstanceUtil(Provider.java:1935)
at java.base/java.security.Provider$Service.newInstance(Provider.java:1910)
... 8 more
My main class which is Main.java like below it doesn't work and i don't know why?
public class Main{
public static void main(String[] args) {
System.setProperty("javax.net.ssl.keyStore", "files/keystore.jks");
//System.setProperty("javax.net.ssl.trustStore", "files/server.cer");
System.setProperty("javax.net.ssl.keyStorePassword", "12345");
new Thread(new ProxyServer(Utils.SERVER_PORT_TO_LISTEN)).start();
}
}

Unable to Instantiate Class while Alter Region adding cache loaded to that region

I have an apache geode setup where there is one locator and one Server. we have a region employee in that. we were trying to implement in-line cache where a cache miss will lookup into database and will fill apache geode, but after deployment of Jars when i am trying to alter the region . It shows exception
Stack Trace:
[error 2021/04/09 15:18:30.513 IST <Function Execution Processor2> tid=0x3a] Error instantiating class: <com.abc.geode.ApacheGeode.EmployeeCacheLoader>
java.lang.RuntimeException: Error instantiating class: <com.abc.geode.ApacheGeode.EmployeeCacheLoader>
at org.apache.geode.management.internal.configuration.domain.DeclarableTypeInstantiator.newInstance(DeclarableTypeInstantiator.java:43)
at org.apache.geode.management.internal.cli.functions.RegionAlterFunction.alterRegion(RegionAlterFunction.java:202)
at org.apache.geode.management.internal.cli.functions.RegionAlterFunction.executeFunction(RegionAlterFunction.java:67)
at org.apache.geode.management.cli.CliFunction.execute(CliFunction.java:37)
at org.apache.geode.internal.cache.MemberFunctionStreamingMessage.process(MemberFunctionStreamingMessage.java:201)
at org.apache.geode.distributed.internal.DistributionMessage.scheduleAction(DistributionMessage.java:372)
at org.apache.geode.distributed.internal.DistributionMessage$1.run(DistributionMessage.java:436)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.geode.distributed.internal.ClusterOperationExecutors.runUntilShutdown(ClusterOperationExecutors.java:475)
at org.apache.geode.distributed.internal.ClusterOperationExecutors.doFunctionExecutionThread(ClusterOperationExecutors.java:393)
at org.apache.geode.logging.internal.executors.LoggingThreadFactory.lambda$newThread$0(LoggingThreadFactory.java:119)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: com.abc.geode.ApacheGeode.EmployeeCacheLoader cannot be cast to org.apache.geode.cache.Declarable
at org.apache.geode.management.internal.configuration.domain.DeclarableTypeInstantiator.newInstance(DeclarableTypeInstantiator.java:34)
public class EmployeeCacheLoader implements CacheLoader<Long,Employee>, Declarable {
#Override
public Employee load(LoaderHelper<Long, Employee> helper) throws CacheLoaderException {
Employee e=new Employee();
e.setEmail("a#b.com");
e.setIdemployee(2L);
return e;
}
#Override
public void close() {
}
#Override
public void init(Properties props) {
}
Things tried
I tried by not implementing Declarable but still no success.
I have not done any change for serializer.
I've just tried the scenario using Apache Geode 1.13.2 and it works just fine, you can find the example here. Do you have multiple versions of the same jar within the server's class path?, that might be the reason for the exception.
Cheers.

How to connect google bigtable outside of google cloud platform

I have a Google Bigtable cluster created.
I'm trying to connect following this tutorial
I was trying to download their cli project and build it, but when I try to execute any command it fails. Also I tried to build my simpler example of connector. Here it is:
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.log4j.Logger;
import java.io.IOException;
import java.util.ArrayList;
public class BigTableTestConnector {
private final static Logger logger = Logger.getLogger(BigTableTestConnector.class);
public void testConnection() throws MasterNotRunningException, ZooKeeperConnectionException {
try {
Connection connection = ConnectionFactory.createConnection();
String tableName = "testTable";
ArrayList<String> columnFamilies = new ArrayList<String>();
columnFamilies.add("columnFamily1");
columnFamilies.add("columnFamily2");
columnFamilies.add("justString");
columnFamilies.add("uhhaha");
Admin admin = connection.getAdmin();
HTableDescriptor tableDescriptor = new HTableDescriptor(tableName);
for (String colFamily : columnFamilies) {
tableDescriptor.addFamily(new HColumnDescriptor(colFamily));
}
admin.createTable(tableDescriptor);
} catch (IOException e) {
e.printStackTrace();
}
logger.info("done");
}
public static void main(String... args) throws Exception {
BigTableTestConnector bttc = new BigTableTestConnector();
bttc.testConnection();
}
}
but when I run it on my local machine, I get following exception
java.io.IOException: java.lang.reflect.InvocationTargetException
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:240)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:218)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:90)
at com.zoomdata.thrift.provider.BigTableTestConnector.testConnection(BigTableTestConnector.java:33)
at com.zoomdata.thrift.provider.BigTableTestConnector.main(BigTableTestConnector.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:238)
... 9 more
Caused by: java.io.IOException: Error getting access token from metadata server at: http://metadata/computeMetadata/v1/instance/service-accounts/default/token
at com.google.cloud.bigtable.hbase.CredentialFactory.getCredentialFromMetadataServiceAccount(CredentialFactory.java:100)
at com.google.cloud.bigtable.hbase.BigtableOptionsFactory.fromConfiguration(BigtableOptionsFactory.java:236)
at org.apache.hadoop.hbase.client.BigtableConnection.<init>(BigtableConnection.java:120)
... 14 more
Caused by: java.io.IOException: ComputeEngineCredentials cannot find the metadata server. This is likely because code is not running on Google Compute Engine.
at com.google.auth.oauth2.ComputeEngineCredentials.refreshAccessToken(ComputeEngineCredentials.java:63)
at com.google.auth.oauth2.OAuth2Credentials.refresh(OAuth2Credentials.java:76)
at com.google.cloud.bigtable.hbase.CredentialFactory.getCredentialFromMetadataServiceAccount(CredentialFactory.java:98)
... 16 more
Caused by: java.net.UnknownHostException: metadata
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
at sun.net.www.http.HttpClient.New(HttpClient.java:308)
at sun.net.www.http.HttpClient.New(HttpClient.java:326)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1168)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1104)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:998)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:932)
at com.google.bigtable.repackaged.com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:93)
at com.google.bigtable.repackaged.com.google.api.client.http.HttpRequest.execute(HttpRequest.java:965)
at com.google.auth.oauth2.ComputeEngineCredentials.refreshAccessToken(ComputeEngineCredentials.java:61)
... 18 more
It said:
ComputeEngineCredentials cannot find the metadata server. This is likely because code is not running on Google Compute Engine.
So does it mean that this code can run only inside Compute Engine?
Is there a way to connect to it from my local computer? Does anyone have any examples of this?
For running locally, you need to make sure that the environment variable GOOGLE_APPLICATION_CREDENTIALS is set to your key.json you got from cloud console. This is the likely cause in your case.

Red5 Application fails to connect

I am attempting to run a basic application on Red5 that just makes an attempt to connect to the red5 server (on localhost). The source for this application is below:
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IConnection;
import org.red5.server.api.scope.IScope;
// import org.red5.server.api.service.ServiceUtils;
/**
* Sample application that uses the client manager.
*
* #author The Red5 Project (red5#osflash.org)
*/
public class Application extends ApplicationAdapter {
/** {#inheritDoc} */
#Override
public boolean connect(IConnection conn, IScope scope, Object[] params) {
return true;
}
/** {#inheritDoc} */
#Override
public void disconnect(IConnection conn, IScope scope) {
super.disconnect(conn, scope);
}
}
My client code is also pretty basic. For brevity, the snippet is below:
public function onCreationComplete(event:FlexEvent) : void {
// setup connection code
connection = new NetConnection();
connection.connect("rtmp://localhost/Player");
connection.addEventListener(NetStatusEvent.NET_STATUS, onConnectionNetStatus);
connection.client = this;
}
public function onConnectionNetStatus(event:NetStatusEvent) : void {
// did we successfully connect
if(event.info.code == "NetConnection.Connect.Success") {
Alert.show("Successful Connection", "Information");
} else {
Alert.show("Unsuccessful Connection "+event.info.code, "Information");
}
Note that I make the alert box show the error code so I can see what happens.
On the client side, when I attempt to connect, I get two failure messages:
Unsuccessful Connection NetConnection.Connect.Closed
Unsuccessful Connection NetConnection.Connect.Rejected
And on the server side I am seeing the following:
[INFO] [NioProcessor-10]
org.red5.server.net.rtmp.codec.RTMPProtocolDecoder - Action connect
[INFO] [NioProcessor-10] org.red5.server.net.rtmp.RTMPConnection -
Setting object encoding to AMF3
[INFO] [NioProcessor-10] org.red5.server.net.rtmp.RTMPHandler - Scope
Player not found on localhost
[WARN] [Red5_Scheduler_Worker-3]
org.red5.server.net.rtmp.RTMPConnection - Closing RTMPMinaConnection
from 127.0.0.1 : 50051 to localhost (in: 3334 out 3256 ), with id 9
due to long handshake
It seems clear that something is wrong due to some kind of mis- configuration. Unfortunately, I have no idea where to look for the problem.
Could someone please give some idea of what is going wrong and how I can fix this? Thank you...
ADDITION: Startup Exception that occurs when running Red5 v1 RC2:
Exception in thread "Launcher:/Player" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with
name 'web.context' defined in ServletContext resource [/WEB-INF/red5-web.xml]:
Unsatisfied dependency expressed through bean property 'clientRegistry': : Cannot find class [org.red5.server.WebScope] for bean with name 'web.scope' defined in ServletContext resource [/WEB-INF/red5-web.xml];
nested exception is java.lang.ClassNotFoundException: org.red5.server.WebScope; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.red5.server.WebScope] for bean with name 'web.scope' defined in ServletContext resource [/WEB-INF/red5-web.xml]; nested exception is java.lang.ClassNotFoundException: org.red5.server.WebScope
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1199)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1091)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.red5.server.tomcat.TomcatLoader$1.run(TomcatLoader.java:593)
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.red5.server.WebScope] for bean with name 'web.scope' defined in ServletContext resource [/WEB-INF/red5-web.xml]; nested exception is java.lang.ClassNotFoundException: org.red5.server.WebScope
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1262)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1331)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:317)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:185)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:833)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1184)
... 11 more
Caused by: java.lang.ClassNotFoundException: org.red5.server.WebScope
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:258)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:417)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1283)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1254)
... 19 more
Another Fact could be that u have 2 Red5.jars so u have to delete one. In my case it worked rly good.
Big Ty for this post
Change org.red5.server.WebScope to org.red5.server.scope.WebScope in your red5-web.xml file.
what version of Red5 is that?
Are there any exceptions when you startup your custom webapp? There might be already an error in the startup of the server that consequently leads to your issue.
Sebastian
The application scope that you are attempting to connect to "Player" does not exist on the server; the log notes this as "Scope Player not found on localhost". What this means in general is that your application didn't load. The reason that it didn't load looks like class package error for WebScope. Change the beans class attribute to org.red5.server.scope.WebScope and try again.

Unable to access a read-only Embedded Derby database from within EAR file deployed on JBoss server

I am trying to access a read-only Embedded Derby database. It is available as myDB.jar. This jar has one folder of the Apache Derby database - myDB (log and seg0 folders and service.properties file). This code works fine when I run from a file with a main method. But, when I package it into EAR and deploy it on server it gives error.
This database is packaged with EAR file and deployed on JBoss 5.0.1 server.
The EAR has following contents:
• myWebApp.war
• myEjbs.jar
• myDB.jar
• META-INF/MANIFEST.MF and META-INF/application.xml
Contents of MANIFEST.MF:
Manifest-Version: 1.0
Class-Path: myDB.jar
myDB.jar is not registered in application.xml
EJB-JAR i.e. myEjbs.jar has the following contents:
• derby.properties
• META-INF/MANIFEST.MF and others such as persistence.xml, etc.
Contents of MANIFEST.MF:
Manifest-Version: 1.0
Class-Path: myDB.jar
• com.xxx.common.DbUtility.class that has the following code accessing the database:
private static String dbURL = "jdbc:derby:jar:(myDB.jar)";
private static String dbName = "myDB";
private static String user = "";
private static String password = "";
Connection con = DriverManager.getConnection(dbURL+ dbName, user, password);
The output of this class is then used by the EJBs in com.xxx.ejbs package.
Following is the error I get:
INFO Loaded database driver: org.apache.derby.jdbc.EmbeddedDriver
INFO SQLException: Failed to start database 'jar:(myDB.jar)myDB' with class loader BaseClassLoader#127627{vfsfile:/C:/jboss-5.0.1.GA/server/default/conf/jboss-service.xml}, see the next exception for details.
INFO java.sql.SQLException: Failed to start database 'jar:(myDB.jar)myDB' with class loader BaseClassLoader#127627{vfsfile:/C:/jboss-5.0.1.GA/server/default/conf/jboss-service.xml}, see the next exception for details.
INFO at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
INFO at java.sql.DriverManager.getConnection(DriverManager.java:582)
INFO at java.sql.DriverManager.getConnection(DriverManager.java:185)
INFO Caused by: java.sql.SQLException: Failed to start database 'jar:(myDB.jar)myDB' with class loader BaseClassLoader#127627{vfsfile:/C:/jboss-5.0.1.GA/server/default/conf/jboss-service.xml}, see the next exception for details.
INFO at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
INFO at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
INFO Caused by: java.sql.SQLException: Java exception: 'myDB.jar (The system cannot find the file specified): java.io.FileNotFoundException'.
INFO at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
INFO at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
INFO at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
INFO at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
INFO Caused by: java.io.FileNotFoundException: myDB.jar (The system cannot find the file specified)
INFO at java.util.zip.ZipFile.open(Native Method)
INFO at java.util.zip.ZipFile.<init>(ZipFile.java:114)
INFO at java.util.zip.ZipFile.<init>(ZipFile.java:131)
INFO at org.apache.derby.impl.io.JarStorageFactory.doInit(Unknown Source)
INFO at org.apache.derby.impl.io.BaseStorageFactory.init(Unknown Source)
Thank you for your reply. I have now tried the following:
(I)
String path = getClass().getClassLoader().getResource("myDB.jar").getPath();
System.out.println("Path found = " + path);
private static String dbURL = "jdbc:derby:jar:" + "(" + path + ")";
private static String dbName = "myDB";
private static String user = "";
private static String password = "";
Connection con = DriverManager.getConnection(dbURL+dbName, user, password);
It still gives the same error. Following is the server log.
INFO Path found = /C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/myDB.jar/
INFO Loaded database driver: org.apache.derby.jdbc.EmbeddedDriver
INFO SQLException: Failed to start database 'jar:(/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/myDB.jar/)myDB' with class loader BaseClassLoader#e6c6d7{vfsfile:/C:/jboss-5.0.1.GA/server/default/conf/jboss-service.xml}, see the next exception for details.
INFO at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
INFO Caused by: java.sql.SQLException: Java exception: 'C:\jboss-5.0.1.GA\server\default\deploy\Main.ear\ myDB.jar (The system cannot find the path specified): java.io.FileNotFoundException'.
INFO at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
INFO Caused by: java.io.FileNotFoundException: C:\jboss-5.0.1.GA\server\default\deploy\Main.ear\ myDB.jar (The system cannot find the path specified)
INFO at java.util.zip.ZipFile.open(Native Method)
INFO at java.util.zip.ZipFile.(ZipFile.java:114)
INFO at java.util.zip.ZipFile.(ZipFile.java:131)
INFO at org.apache.derby.impl.io.JarStorageFactory.doInit(Unknown Source)
Following is the output when classes are being loaded by JBoss initially:
BaseClassLoader#a75818{vfszip:/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/} with policy VFSClassLoaderPolicy#88a588{name=vfszip:/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/ domain=null roots=[MemoryContextHandler#19639558[path= context=vfsmemory://ak42v-bfhwq-ger46v84-1-ger477uj-20 real=vfsmemory://ak42v-bfhwq-ger46v84-1-ger477uj-20], DelegatingHandler#7111491[path=Main.ear context=file:/C:/jboss-5.0.1.GA/server/default/deploy/ real=file:/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear], DelegatingHandler#1948811[path=Main.ear/myEJBs.jar context=file:/C:/jboss-5.0.1.GA/server/default/deploy/ real=file:/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/myEJBs.jar], DelegatingHandler#4545587[path=Main.ear/ myDB.jar context=file:/C:/jboss-5.0.1.GA/server/default/deploy/ real=file:/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/ myDB.jar], com.xxx.common, com.xxx.ejb, myDB, myDB.seg0, META-INF, myDB.log, …
So it looks like the myDB.jar is in the classpath and the database folder myDB is also loaded.
(II)
Then I tried the following:
private static String dbURL_nfdc = "jdbc:derby:/";
private static String dbName = "myDB";
private static String user = "";
private static String password = "";
Connection con = DriverManager.getConnection(dbURL+dbName, user, password);
I again get an error, but, now I do not get the FileNotFoundException:
INFO java.sql.SQLException: Database '/myDB' not found.
INFO Caused by: java.sql.SQLException: Database '/myDB' not found.
Looks like you have pointed me in the right direction, but, I am not able to find the reason for this error.
(III)
I also tried the following:
private static String dbURL_nfdc = "jdbc:derby:"; (No / )
private static String dbName = "myDB";
private static String user = "";
private static String password = "";
Connection con = DriverManager.getConnection(dbURL+dbName, user, password);
But, get the same SQLException.
Is it possible that JBoss is treating myDB as a java package and not a simple file folder?
The following worked:
private static String dbURL_nfdc = "jdbc:derby:classpath:/";
private static String dbName = "myDB";
private static String user = "";
private static String password = "";
Connection con = DriverManager.getConnection(dbURL+dbName, user, password);
Thank you so much for leading me in the right direction. Appreciate your help!!!
Since your database jar is inside your same EJB ear package, I think it is supposed to be "in the classpath", so you should try following the "in the classpath" section of the docs at http://db.apache.org/derby/docs/10.6/devguide/cdevdvlp24155.html#cdevdvlp24155.
That is, I don't think you want to use the "jar" sub-protocol.
Alternatively, if you are going to use the "jar" sub-protocol, then I think that the part inside the parentheses should be the full filesystem path of your ejb ear file.