Hello I'm trying to update my app on heroku. When I build my app this error appears:
Caused by: java.lang.NullPointerException: null
at java.net.URI$Parser.parse(URI.java:3042) ~[na:1.8.0_221]
at java.net.URI.<init>(URI.java:588) ~[na:1.8.0_221]
at pl.jawegiel.util.DbUtil.getConnection(DbUtil.java:19) ~[classes/:na]
at pl.jawegiel.dao.UsersBasicInfoDao.<init>(UsersBasicInfoDao.java:17) ~[classes/:na]
at pl.jawegiel.dao.UsersDao.<init>(UsersDao.java:27) ~[classes/:na]
at pl.jawegiel.listener.SessionListener.<init>(SessionListener.java:19) ~[classes/:na]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_221]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_221]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_221]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_221]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
... 64 common frames omitted
where my DbUtil class looks like this:
public class DbUtil {
public static Connection getConnection() throws URISyntaxException, SQLException {
URI dbUri = new URI(System.getenv("DATABASE_URL"));
String username = dbUri.getUserInfo().split(":")[0];
String password = dbUri.getUserInfo().split(":")[1];
String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath();
return DriverManager.getConnection(dbUrl, username, password);
}
}
I did exactly as Heroku tutorial says but in vain. Help me please.
It is because of this line
System.getenv("DATABASE_URL")
The program could not find the system environment variable on heroku.
You will have to add the environment variable value using config var or set define database url inside the class and use it.
Related
for a school project I'm trying to create my own SOAP web service.
While doing some work an error occur.
public class ServerMain {
private static final Logger LOGGER = Logger.getAnonymousLogger();
public static void main(String[] args) {
try{
Endpoint.publish("http://localhost:8976/s19103/people",
new PersonServiceImpl());
LOGGER.info("Service started");
System.out.println("START");
}
catch (Exception e){
e.printStackTrace();
}
}}
I got this error
Exception in thread "main" java.util.ServiceConfigurationError: javax.xml.ws.spi.Provider: Provider com.sun.xml.ws.spi.ProviderImpl could not be instantiated
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:581)
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:803)
at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:721)
at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1394)
at javax.xml.ws.spi.Provider.getProviderUsingServiceLoader(Provider.java:180)
at javax.xml.ws.spi.Provider.provider(Provider.java:140)
at javax.xml.ws.Endpoint.publish(Endpoint.java:255)
at example.HelloWorld.main(HelloWorld.java:17)
Caused by: java.lang.NoClassDefFoundError: javax/activation/DataSource
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.<clinit>(RuntimeBuiltinLeafInfoImpl.java:461)
at com.sun.xml.bind.v2.model.impl.RuntimeTypeInfoSetImpl.<init>(RuntimeTypeInfoSetImpl.java:65)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:133)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:85)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.<init>(ModelBuilder.java:156)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.<init>(RuntimeModelBuilder.java:93)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:455)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:303)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:142)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1174)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:162)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:262)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:249)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:442)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:652)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:599)
at com.sun.xml.ws.spi.ProviderImpl$2.run(ProviderImpl.java:274)
at com.sun.xml.ws.spi.ProviderImpl$2.run(ProviderImpl.java:271)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.ws.spi.ProviderImpl.getEPRJaxbContext(ProviderImpl.java:271)
at com.sun.xml.ws.spi.ProviderImpl.<clinit>(ProviderImpl.java:96)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:779)
... 6 more
Caused by: java.lang.ClassNotFoundException: javax.activation.DataSource
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 36 more
What does it mean and what do I have to do to run my program?
Even when I try to run the automaticaly generated example HelloWorld I get the same error.
I just instaled MySQL server and made one database using Terminal- on ubuntu, and the server works, my database is shown properly and my table is shown also properly.
But when I try to run a program in eclipse, it trows an exception. First was a SSL exception which I fixed with ?autoReconnect=true&useSSL=false.
So now, I get another exception. It says it can not connect to database and gives up after three tries.
I also tried some solutions from this forum, but with no success.
...
Im using drivers version 5.1.42.
Any solutions?
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class MySql {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Imenik?autoReconnect=true&useSSL=false","root","******");
PreparedStatement ps = conn.prepareStatement("select * from imenik");
ResultSet result = ps.executeQuery();
while(result.next()) {
System.out.println(result.getString(1) + " " +result.getString(2) + " " +result.getString(3) );
}
}}
And this would be an exception:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
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:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2104)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2029)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
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:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at MySql.main(MySql.java:11)
Caused by: java.sql.SQLException: Unknown system variable
'query_cache_size'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2444)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1381)
at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3766)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3229)
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2067)
... 13 more
It might be problem of your given password for the database, you can use below solution:
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Imenik?autoReconnect=true&useSSL=false","root","root");
PreparedStatement ps = (PreparedStatement) conn.prepareStatement("select * from imenik");
ResultSet result = ps.executeQuery();
while(result.next()) {
System.out.println(result.getString(1) + " " +result.getString(2) + " " +result.getString(3) );
}
tested with mysql-connector-java-6.0.6.jar
Hi I currently have an WAS 7.0.29 and we've planned to update it to fix pack 41.
Upon the installation of the Fix pack I have encountered this:
[11/10/16 19:32:24:505 SGT] 00000000 UserRegistryC E SECJ0281E: Error creating user registry object. The exception is java.lang.NoClassDefFoundError: com.dummy.registry.CustomRegistry (initialization failure)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:139)
at java.lang.Class.forName(Class.java:294)
at com.ibm.ws.security.registry.UserRegistryImpl.initialize(UserRegistryImpl.java:225)
at com.ibm.ws.security.config.UserRegistryConfigImpl.do_createRegistryObjects(UserRegistryConfigImpl.java:686)
at com.ibm.ws.security.config.UserRegistryConfigImpl.createRegistryObjects(UserRegistryConfigImpl.java:643)
at com.ibm.ws.security.config.UserRegistryConfigImpl.getUserRegistryImpl(UserRegistryConfigImpl.java:628)
at com.ibm.ws.security.config.UserRegistryConfigImpl.getString(UserRegistryConfigImpl.java:850)
at com.ibm.ws.security.config.UserRegistryConfigImpl.getPrincipalName(UserRegistryConfigImpl.java:577)
at com.ibm.ws.security.config.CSIv2ConfigImpl.initializeOnServer(CSIv2ConfigImpl.java:723)
at com.ibm.ws.security.config.CSIv2ConfigImpl.initialize(CSIv2ConfigImpl.java:1151)
at com.ibm.ws.security.config.CSIv2ConfigImpl.<init>(CSIv2ConfigImpl.java:100)
at com.ibm.ws.security.config.SecurityConfigObjectFactoryImpl.createCSIv2Config(SecurityConfigObjectFactoryImpl.java:116)
at com.ibm.ws.security.config.SecurityObjectLocator.do_getCSIv2Config(SecurityObjectLocator.java:852)
at com.ibm.ejs.ras.RasHelper.printStackTrace(RasHelper.java:368)
at com.ibm.ejs.ras.RasHelper.throwableToString(RasHelper.java:349)
at com.ibm.ejs.ras.MessageEvent6.convertParameters(MessageEvent6.java:346)
at com.ibm.ejs.ras.MessageEvent6.<init>(MessageEvent6.java:221)
at com.ibm.ejs.ras.Tr.fireMessageEvent(Tr.java:1538)
at com.ibm.ejs.ras.Tr.error(Tr.java:733)
at com.ibm.ws.security.config.UserRegistryConfigImpl.do_createRegistryObjects(UserRegistryConfigImpl.java:696)
at com.ibm.ws.security.config.UserRegistryConfigImpl.createRegistryObjects(UserRegistryConfigImpl.java:643)
at com.ibm.ws.security.config.UserRegistryConfigImpl.getUserRegistryImpl(UserRegistryConfigImpl.java:628)
at com.ibm.ws.security.config.UserRegistryConfigImpl.getString(UserRegistryConfigImpl.java:850)
at com.ibm.ws.security.config.UserRegistryConfigImpl.getPrincipalName(UserRegistryConfigImpl.java:577)
at com.ibm.ws.security.config.CSIv2ConfigImpl.initializeOnServer(CSIv2ConfigImpl.java:723)
at com.ibm.ws.security.config.CSIv2ConfigImpl.initialize(CSIv2ConfigImpl.java:1151)
at com.ibm.ws.security.config.CSIv2ConfigImpl.<init>(CSIv2ConfigImpl.java:100)
at com.ibm.ws.security.config.SecurityConfigObjectFactoryImpl.createCSIv2Config(SecurityConfigObjectFactoryImpl.java:116)
at com.ibm.ws.security.config.SecurityObjectLocator.do_getCSIv2Config(SecurityObjectLocator.java:852)
at com.ibm.ws.security.config.SecurityObjectLocator.getCSIv2Config(SecurityObjectLocator.java:882)
at com.ibm.ws.security.config.SecurityObjectLocator.getCSIv2Config(SecurityObjectLocator.java:873)
at com.ibm.ws.security.auth.ContextManagerImpl.getProperty(ContextManagerImpl.java:2102)
at com.ibm.ws.security.auth.ContextManagerImpl.getProperty(ContextManagerImpl.java:2141)
at com.ibm.websphere.security.WSSecurityException.printStackTrace(WSSecurityException.java:230)
at com.ibm.ffdc.util.formatting.IncidentReportHeader.writeTo(IncidentReportHeader.java:77)
at com.ibm.ffdc.util.provider.IncidentStream.write(IncidentStream.java:207)
at com.ibm.ffdc.util.provider.IncidentLogger.writeHeader(IncidentLogger.java:70)
at com.ibm.ffdc.util.provider.IncidentLogger.writeIncidentTo(IncidentLogger.java:61)
at com.ibm.ws.ffdc.impl.FfdcProvider.logIncident(FfdcProvider.java:206)
at com.ibm.ws.ffdc.impl.FfdcProvider.logIncident(FfdcProvider.java:135)
at com.ibm.ffdc.util.provider.FfdcProvider.log(FfdcProvider.java:259)
at com.ibm.ws.ffdc.impl.FfdcProvider.log(FfdcProvider.java:148)
at com.ibm.ffdc.util.provider.IncidentEntry.log(IncidentEntry.java:105)
at com.ibm.ffdc.util.provider.Ffdc.log(Ffdc.java:90)
at com.ibm.ws.ffdc.FFDCFilter.processException(FFDCFilter.java:114)
at com.ibm.ws.security.config.UserRegistryConfigImpl.do_createRegistryObjects(UserRegistryConfigImpl.java:694)
at com.ibm.ws.security.config.UserRegistryConfigImpl.createRegistryObjects(UserRegistryConfigImpl.java:643)
at com.ibm.ws.security.config.UserRegistryConfigImpl.getUserRegistryImpl(UserRegistryConfigImpl.java:628)
at com.ibm.ws.security.core.distSecurityComponentImpl.getRealmFromUserRegistry(distSecurityComponentImpl.java:2808)
at com.ibm.ws.security.core.distSecurityComponentImpl.initialize(distSecurityComponentImpl.java:356)
at com.ibm.ws.security.core.SecurityComponentImpl.initialize(SecurityComponentImpl.java:94)
at com.ibm.ws.runtime.component.ContainerHelper.initWsComponent(ContainerHelper.java:1191)
at com.ibm.ws.runtime.component.ContainerHelper.initializeComponent(ContainerHelper.java:1098)
at com.ibm.ws.runtime.component.ContainerHelper.initializeComponents(ContainerHelper.java:900)
at com.ibm.ws.runtime.component.ContainerImpl.initializeComponents(ContainerImpl.java:776)
at com.ibm.ws.runtime.component.ContainerImpl.initializeComponents(ContainerImpl.java:750)
at com.ibm.ws.runtime.component.ServerImpl.initialize(ServerImpl.java:349)
at com.ibm.ws.runtime.WsServerImpl.bootServerContainer(WsServerImpl.java:280)
at com.ibm.ws.runtime.WsServerImpl.start(WsServerImpl.java:214)
at com.ibm.ws.runtime.WsServerImpl.main(WsServerImpl.java:666)
at com.ibm.ws.runtime.WsServer.main(WsServer.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.ibm.wsspi.bootstrap.WSLauncher.launchMain(WSLauncher.java:213)
at com.ibm.wsspi.bootstrap.WSLauncher.main(WSLauncher.java:93)
at com.ibm.wsspi.bootstrap.WSLauncher.run(WSLauncher.java:74)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:340)
at org.eclipse.core.launcher.Main.basicRun(Main.java:282)
at org.eclipse.core.launcher.Main.run(Main.java:981)
at com.ibm.wsspi.bootstrap.WSPreLauncher.launchEclipse(WSPreLauncher.java:341)
at com.ibm.wsspi.bootstrap.WSPreLauncher.main(WSPreLauncher.java:111)
Caused by: java.lang.ExceptionInInitializerError
at java.lang.J9VMInternals.initialize(J9VMInternals.java:221)
at com.ibm.websphere.ras.Manager.createRASTraceLogger(Manager.java:241)
at com.dummy.registry.CustomRegistry.<clinit>(CustomRegistry.java:126)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:199)
at java.lang.Class.forName(Class.java:294)
at com.ibm.ws.security.registry.UserRegistryImpl.initialize(UserRegistryImpl.java:225)
at com.ibm.ws.security.config.UserRegistryConfigImpl.do_createRegistryObjects(UserRegistryConfigImpl.java:686)
... 36 more
Caused by: java.security.AccessControlException: Access denied (java.util.PropertyPermission com.ibm.ws.ffdc.SupportORBFFDC read)
at java.security.AccessController.throwACE(AccessController.java:121)
at java.security.AccessController.checkPermission(AccessController.java:194)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:544)
at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1293)
at java.lang.System.getProperty(System.java:404)
at java.lang.System.getProperty(System.java:388)
at com.ibm.websphere.ras.WsJrasTraceLogger.<clinit>(WsJrasTraceLogger.java:98)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:199)
... 43 more
.
My guess is that the issue is in the CustomRegistry that we have made which looks like this:
public class CustomRegistry implements UserRegistry {
protected static RASTraceLogger traceLogger;
private static RASMessageLogger msgLogger;
static {
Manager mgr = Manager.getManager();
traceLogger = mgr.createRASTraceLogger("MyWebsite", "Authentication", "Registry", CustomRegistry.class.getName());
msgLogger = mgr.createRASMessageLogger("MyWebsite", "Authentication", "Registry", CustomRegistry.class.getName());
msgLogger.setMessageFile("com.dummy.registry.RegistryMessages");
}
It points the usage of mgr.createRASTraceLogger in the CustomRegistry but I'm not sure what is the right approach for it.
Right now, I can't even start my server.
Your suggestions will be a great help! :)
I wanted to know if and how can I connect to HBaseTestTable which I made using
(org.apache.hadoop.hbase.HBaseTestingUtility;) via Phoenix. I want to have a successful connection to Hbase then insert into the Test table and retrieve data from the Test table. I have been able to create a HbaseTable. But unable to connect to it via Phoenix. Also unable to use writeToPhoenix function.
I am sharing the code which I have written:
#BeforeClass
public static void init() throws Exception {
testingUtility = new HBaseTestingUtility();
testingUtility.startMiniCluster();
hbaseConfiguration = testingUtility.getHBaseCluster().getConfiguration();
String zkQuorum = "localhost:" + testingUtility.getZkCluster().getClientPort();
Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
java.sql.Connection connection = DriverManager.getConnection("jdbc:phoenix:"+zkQuorum);
connection.setAutoCommit(true);
try {
Statement statement = connection.createStatement();
statement.executeUpdate("CREATE TABLE TEST(" +
"KEY VARCHAR NOT NULL," +
"VALUE1 VARCHAR NOT NULL," +
"VALUE2 VARCHAR NOT NULL," +
"CONSTRAINT PK PRIMARY KEY(KEY)" +
")");
connection.commit();
log.info("HBase table via Phoenix created successfully.");
} catch (Exception e) {
e.printStackTrace();
}
}
Stack Trace :
java.lang.ClassNotFoundException: org.apache.phoenix.jdbc.PhoenixDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
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:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
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:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Thanks.
You need to add the Phoenix jar file to your classpath in IntelliJ
Here is the error.
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:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1117)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:355)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2461)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2498)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:822)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
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:408)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at eventmanagementsystem.infinity.dbHandler.buildConnection(dbHandler.java:43)
at eventmanagementsystem.infinity.dbHandler.getParticipantResultSet(dbHandler.java:395)
at eventmanagementsystem.infinity.ParticipantList.populateList(ParticipantList.java:96)
at eventmanagementsystem.infinity.EMS.<init>(EMS.java:31)
at eventmanagementsystem.infinity.EventManagementSystemInfinity.main(EventManagementSystemInfinity.java:25)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:244)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:259)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:305)
... 19 more
May 24, 2015 3:48:58 PM eventmanagementsystem.infinity.EMS <init>
SEVERE: null
java.lang.NullPointerException
at eventmanagementsystem.infinity.dbHandler.getParticipantResultSet(dbHandler.java:396)
at eventmanagementsystem.infinity.ParticipantList.populateList(ParticipantList.java:96)
at eventmanagementsystem.infinity.EMS.<init>(EMS.java:31)
at eventmanagementsystem.infinity.EventManagementSystemInfinity.main(EventManagementSystemInfinity.java:25)
BUILD SUCCESSFUL (total time: 21 seconds)
Here is the code.
public static Connection buildConnection()
{
try{
//Class.forName("org.apache.derby.jdbc.ClientDriver");
//Class.forName("oracle.jdbc.driver.OracleDriver");
Class.forName("com.mysql.jdbc.Driver");
//String connString = "jdbc:derby://localhost:4040/EventManagementSystem";
//String username = "Event";
//String password = "event";
//String username = "system";
//String password = "a1234";
String JDBC_DRIVER = "com.mysql.jdbc.Driver";
String DB_URL = "jdbc:mysql://localhost:3306/user";
String USER = "root";
String PASS = "a1234";
//Connection conn = DriverManager.getConnection(connString,username,password);
//Connection conn = DriverManager.getConnection("jdbc:oracle:thin:#oracle-prod:1521:OPROD",username,password);
Connection conn = DriverManager.getConnection(DB_URL,USER,PASS);
return conn;
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
I think the problem is with the DB_URL but I am not very sure. I have added mysql-connector jar as well. It cannot access the database that I have created. The error list also shows that connection is refused but I am not sure why is that so.