MongoTimeoutException: Error While Using MongoDB with Trino - mongodb

I'm passing mongodb.properties as
connector.name=mongodb mongodb.seeds=127.0.0.1:27017 mongodb.credentials=username:password#database
But when running the catalog after passing the query it is giving error as
Query 20210312_110147_00003_zxyd4 failed: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1#469d4507. Client view of cluster state is {type=REPLICA_SET, servers=[{address=hostname:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}]
Can Someone Help. Am i doing something wrong while doing the connection?
Note:- I'm running trino locally using single machine for testing, that functions as both a coordinator and worker and mongodb is on some other server but i'm routing the localhost to the desired server using ssh

It's working while using this JAVA Code, Use these two mongodb-driver-core-3.7.1-javadoc.jar,mongo-java-driver-3.3.0.jar files to compile and run below code
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import java.util.Collections;
import org.bson.Document;
import java.util.List;
public class MongoSession
{
public static void main(String[] args)
{
ServerAddress seed = new ServerAddress("127.0.0.1:27017");
MongoCredential credential = MongoCredential.createCredential("user", "database", "password".toCharArray());
MongoClient client = new MongoClient(seed, Collections.singletonList(credential), MongoClientOptions.builder().build());
client.getDatabase("database").runCommand(new Document("ping", 1));
for (String name : client.getDatabase("database").listCollectionNames()) {
System.out.println(name);
}
}
}
Thanks to MongoDB Community for such a Quick Response
Jira:- https://jira.mongodb.org/browse/JAVA-4076?focusedCommentId=3673048&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-3673048

Related

Error when trying to access Kafka with Quarkus in native mode

I tried a simple sample code to test access to a "kerberized" Kafka from Quarkus 2.2.2 with smallrye-reactive-messaging-kafka :
package org.acme;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.eclipse.microprofile.reactive.messaging.Incoming;
import javax.enterprise.context.ApplicationScoped;
#ApplicationScoped
public class MyTopicConsumer {
#Incoming("in")
public void consume(ConsumerRecord<String, String> record) {
System.out.println("read from Kafka : " + record.value() ) ;
}
}
Kafkas is behind Kerberos, so i used an application.properties like this :
quarkus.ssl.native=true
quarkus.native.enable-all-security-services=true
mp.messaging.incoming.in.group.id=my-group
mp.messaging.incoming.in.auto.commit.interval.ms=1000
mp.messaging.incoming.in.security.protocol=SASL_SSL
mp.messaging.incoming.in.sasl.kerberos.service.name=kafka
mp.messaging.incoming.in.sasl.mechanism=GSSAPI
mp.messaging.incoming.in.sasl.jaas.config=com.sun.security.auth.module.Krb5LoginModule "required" doNotPrompt=true useKeyTab=true storeKey=true serviceName="kafka" keyTab="<keytab>" principal="<principal>" useTicketCache=false;
mp.messaging.incoming.in.ssl.truststore.location=<location>
mp.messaging.incoming.in.ssl.truststore.password=<password>
mp.messaging.incoming.in.connector=smallrye-kafka
mp.messaging.incoming.in.topic=<topic>
mp.messaging.incoming.in.auto.offset.reset=earliest
mp.messaging.incoming.in.enable.auto.commit=false
mp.messaging.incoming.in.bootstrap.servers=<list of servers>
It works nicely in jvm mode, but fails in native mode (graalvm-ce-java11-21.2.0) with this error :
ERROR [io.sma.rea.mes.provider] (main) SRMSG00230: Unable to create the publisher or subscriber during initialization: org.apache.kafka.common.KafkaException: Failed to construct kafka consumer
at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:823)
at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:665)
at io.smallrye.reactive.messaging.kafka.impl.ReactiveKafkaConsumer.<init>(ReactiveKafkaConsumer.java:80)
at io.smallrye.reactive.messaging.kafka.impl.KafkaSource.<init>(KafkaSource.java:85)
at io.smallrye.reactive.messaging.kafka.KafkaConnector.getPublisherBuilder(KafkaConnector.java:182)
at io.smallrye.reactive.messaging.kafka.KafkaConnector_ClientProxy.getPublisherBuilder(KafkaConnector_ClientProxy.zig:159)
at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory.createPublisherBuilder(ConfiguredChannelFactory.java:190)
at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory.register(ConfiguredChannelFactory.java:153)
at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory.initialize(ConfiguredChannelFactory.java:125)
at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory_ClientProxy.initialize(ConfiguredChannelFactory_ClientProxy.zig:189)
at java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
at io.smallrye.reactive.messaging.extension.MediatorManager.start(MediatorManager.java:189)
at io.smallrye.reactive.messaging.extension.MediatorManager_ClientProxy.start(MediatorManager_ClientProxy.zig:220)
at io.quarkus.smallrye.reactivemessaging.runtime.SmallRyeReactiveMessagingLifecycle.onApplicationStart(SmallRyeReactiveMessagingLifecycle.java:41)
at io.quarkus.smallrye.reactivemessaging.runtime.SmallRyeReactiveMessagingLifecycle_Observer_onApplicationStart_4e8937813d9e8faff65c3c07f88fa96615b70e70.notify(SmallRyeReactiveMessagingLifecycle_Observer_onApplicationStart_4e8937813d9e8faff65c3c07f88fa96615b70e70.zig:111)
at io.quarkus.arc.impl.EventImpl$Notifier.notifyObservers(EventImpl.java:300)
at io.quarkus.arc.impl.EventImpl$Notifier.notify(EventImpl.java:282)
at io.quarkus.arc.impl.EventImpl.fire(EventImpl.java:70)
at io.quarkus.arc.runtime.ArcRecorder.fireLifecycleEvent(ArcRecorder.java:128)
at io.quarkus.arc.runtime.ArcRecorder.handleLifecycleEvents(ArcRecorder.java:97)
at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy_0(LifecycleEventsBuildStep$startupEvent1144526294.zig:87)
at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy(LifecycleEventsBuildStep$startupEvent1144526294.zig:40)
at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:623)
at io.quarkus.runtime.Application.start(Application.java:101)
at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:101)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:42)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:119)
at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
Caused by: org.apache.kafka.common.KafkaException: org.apache.kafka.common.KafkaException: Could not find a public no-argument constructor for org.apache.kafka.common.security.kerberos.KerberosLogin
at org.apache.kafka.common.network.SaslChannelBuilder.configure(SaslChannelBuilder.java:184)
at org.apache.kafka.common.network.ChannelBuilders.create(ChannelBuilders.java:192)
at org.apache.kafka.common.network.ChannelBuilders.clientChannelBuilder(ChannelBuilders.java:81)
at org.apache.kafka.clients.ClientUtils.createChannelBuilder(ClientUtils.java:105)
at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:737)
... 30 more
I tried a few changes suggested by some posts, but with no effect.
Can anyone suggest how to fix or workaround this ?
Thanks
It is seems that the code doesn't contain the constructor org.apache.kafka.common.security.kerberos.KerberosLogin.
Have you try to add the class as describe in https://quarkus.io/guides/writing-native-applications-tips#registering-for-reflection
Maybe you need to add line in your configuration file
quarkus.native.additional-build-args=-H:ReflectionConfigurationFiles=reflection-config.json
And add the class org.apache.kafka.common.security.kerberos.KerberosLogin in reflection-config.json as describe here https://quarkus.io/guides/writing-native-applications-tips#using-a-configuration-file

Invalid mongo configuration, either uri or host/port/credentials must be specified

I'm getting this exception :
Caused by: java.lang.IllegalStateException: Invalid mongo configuration, either uri or host/port/credentials must be specified
at org.springframework.boot.autoconfigure.mongo.MongoProperties.createMongoClient(MongoProperties.java:207)
at org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration.mongo(MongoAutoConfiguration.java:73)
at org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration$$EnhancerBySpringCGLIB$$15f9b896.CGLIB$mongo$1(<generated>)
at org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration$$EnhancerBySpringCGLIB$$15f9b896$$FastClassBySpringCGLIB$$c0338f6a.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
at org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration$$EnhancerBySpringCGLIB$$15f9b896.mongo(<generated>)
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:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 25 common frames omitted
Here is my application.yml content :
spring:
data:
mongodb:
uri: mongodb://develop:d3VeL0p$#<my_host>:27017/SHAM
Here is my configuration class :
package com.me.service.testservice.config;
import com.mongodb.MongoClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
#Configuration
#EnableMongoRepositories(basePackages = {"com.me.service.testservice.repository"}, considerNestedRepositories = true)
public class SpringMongoConfiguration {
#Bean
public MongoTemplate mongoTemplate() throws Exception {
return new MongoTemplate(new MongoClient("<my_host>"), "SHAM");
}
}
Now I'm getting this stack trace when starting without failing, it looks like user develop doesn't have the right to connect:
Caused by: com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server phelbwlabect003.karmalab.net:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }
at com.mongodb.connection.CommandHelper.createCommandFailureException(CommandHelper.java:170)
at com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:123)
at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32)
at com.mongodb.connection.SaslAuthenticator.sendSaslStart(SaslAuthenticator.java:117)
at com.mongodb.connection.SaslAuthenticator.access$000(SaslAuthenticator.java:37)
at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:50)
... 9 common frames omitted
You are mixing the uri style connection settings with the individual properties style settings.
Either use
spring:
data:
mongodb:
host: localhost
port: 27017
database: SHAM_TEST
username: develop
password: pass
Or
spring:
data:
mongodb:
uri:mongodb://develop:pass#localhost:27017/SHAM_TEST
If your project has more then one application.properties/application.yml file, sometime they both conflicts if one has URI and other has Host/Port/Credential.
This result in the error "Invalid mongo configuration, either uri or host/port/credentials must be specified"
To Avoid the conflict, make sure you either use URI or Host/Port/Credential in all.
The issue was authentication-database was missing.
Here is now the working configuration :
spring:
data:
mongodb:
host: <my_host>
username: develop
password: d3VeL0p$
port: 27017
database: SHAM
repositories:
enabled: true
authentication-database: admin
If you are using application.properties file to store your configuration, Use the following structure.
spring.data.mongodb.host = localhost
spring.data.mongodb.port = 27017
spring.data.mongodb.database = SHAM_TEST
spring.data.mongodb.username = develop
spring.data.mongodb.password = pass
This issue appears with mongo version 4.x,
spring or spring boot supports version 2.x only so when we try to connect with mongo 4 this error appears:
Downgrade your mongo from 4.x to 3.x or lower.
If not, then change these placeholders.
Change from :
spring.data.mongodb.host= localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database= your db name
spring.data.mongodb.username= something
spring.data.mongodb.password= ***
-to-
mongo.replica.hosts=localhost:27017
mongo.dbname= your db name
mongo.username= something
mongo.password= ***

Unable to access an EJB deployed in jboss as 7

I have deployed an EJB in Jboss As 7.0.
Following is what the deployment logs says about the JNDI binding of EJB.
19:21:43,269 INFO
[org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor]
(MSC service thread 1-1) JNDI bindings for session bean named
ManageEmployeeBean in deployment unit deployment "EJBTest1.jar" are as
follows:
java:global/EJBTest1/ManageEmployeeBean!com.test.ejb.businessimpl.ManageEmployeeBeanRemote
java:app/EJBTest1/ManageEmployeeBean!com.test.ejb.businessimpl.ManageEmployeeBeanRemote
java:module/ManageEmployeeBean!com.test.ejb.businessimpl.ManageEmployeeBeanRemote
java:jboss/exported/EJBTest1/ManageEmployeeBean!com.test.ejb.businessimpl.ManageEmployeeBeanRemote
java:global/EJBTest1/ManageEmployeeBean
java:app/EJBTest1/ManageEmployeeBean java:module/ManageEmployeeBean
This is how my client class looks like.
package com.test.ejb.test;
import java.util.Hashtable;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.test.ejb.bean.Employee;
import com.test.ejb.businessimpl.ManageEmployeeBean;
import com.test.ejb.businessimpl.ManageEmployeeBeanRemote;
public class Client {
private static InitialContext initialContext;
public static void main(String[] args){
try {
getInitialContext();
System.out.println("CTX:"+initialContext);
} catch (NamingException e) {
e.printStackTrace();
}
try {
System.out.println("Looking up EJB !!");
ManageEmployeeBeanRemote remote =
(ManageEmployeeBeanRemote)initialContext.lookup("/EJBTest1/ManageEmployeeBean!com.test.ejb.businessimpl.ManageEmployeeBeanRemote");
System.out.println("setting employee..............");
Employee employee = new Employee();
employee.setFirstName("Renjith");
employee.setLastName("Ravi");
System.out.println("Adding employee");
remote.addEmployee(employee);
} catch (NamingException e) {
e.printStackTrace();
}
}
public static InitialContext getInitialContext() throws NamingException {
if (initialContext == null) {
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
prop.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
prop.put(Context.PROVIDER_URL, "remote://localhost:4447");
prop.put(Context.SECURITY_PRINCIPAL, "renjith");
prop.put(Context.SECURITY_CREDENTIALS, "user");
initialContext = new InitialContext(prop);
}
return initialContext;
}
}
Client is not able to find the service when I run it.
CTX:javax.naming.InitialContext#40964823
Looking up EJB !!
javax.naming.CommunicationException: Could not obtain connection to any of these urls: remote://localhost:4447 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server remote:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server remote:1099 [Root exception is java.net.UnknownHostException: remote: Name or service not known]]]
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1416)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:596)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:589)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at com.test.ejb.test.Client.main(Client.java:29)
Caused by: javax.naming.CommunicationException: Failed to connect to server remote:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server remote:1099 [Root exception is java.net.UnknownHostException: remote: Name or service not known]]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:269)
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1387)
... 4 more
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server remote:1099 [Root exception is java.net.UnknownHostException: remote: Name or service not known]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:243)
... 5 more
Caused by: java.net.UnknownHostException: remote: Name or service not known
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
at java.net.InetAddress.getAllByName0(InetAddress.java:1246)
at java.net.InetAddress.getAllByName(InetAddress.java:1162)
at java.net.InetAddress.getAllByName(InetAddress.java:1098)
at java.net.InetAddress.getByName(InetAddress.java:1048)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:76)
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:239)
... 5 more
Can anyone tell me what am i missing here?
I saw lots of threads on similar topic in stackoverflow, but none of them helped me!!
You are attempting to use the EJB Remote client from JBoss AS 5 (or earlier).
You need to use the JBoss AS 7 EJB Remote client and configure it as per the documentation at AS7 JNDI Reference under the Remote JNDI heading.

Acra doesn't send JSON request to my own server

I'm trying to implement ACRA into my Android Application. I'm trying to send crash report with JSON via POST. To do that I have configured ACRA and created the following class:
import android.app.Application;
import org.acra.ACRA;
import org.acra.ReportField;
import org.acra.ReportingInteractionMode;
import org.acra.annotation.*;
import org.acra.sender.HttpSender;
#ReportsCrashes(
formUri = "https://mySite/myFolder/report.php",
reportType = HttpSender.Type.JSON,
httpMethod = HttpSender.Method.POST,
formUriBasicAuthLogin = "username",
formUriBasicAuthPassword = "password",
formKey = "", // This is required for backward compatibility but not used
customReportContent = {
ReportField.APP_VERSION_CODE,
ReportField.APP_VERSION_NAME,
ReportField.ANDROID_VERSION,
ReportField.PACKAGE_NAME,
ReportField.REPORT_ID,
ReportField.BUILD,
ReportField.STACK_TRACE
},
mode = ReportingInteractionMode.SILENT)
public class Crazy extends Application {
public void onCreate() {
super.onCreate();
ACRA.init(this);
}
}
I am currently doing my application crash voluntarily, to test ACRA. When the app crash, the logcat show me that error:
09-18 14:25:53.943 20309-20324/myPackage I/ACRA﹕ Sending file 1411042794000-approved.stacktrace
09-18 14:25:53.958 20309-20309/myPackage D/OpenGLRenderer﹕ Enabling debug mode 0
09-18 14:25:53.968 20309-20324/myPackage D/ACRA﹕ Connect to https://mySite/myFolder/report.php
09-18 14:25:53.983 20309-20312/myPackage D/dalvikvm﹕ GC_CONCURRENT freed 414K, 15% free 9757K/11399K, paused 13ms+13ms, total 58ms
09-18 14:25:54.008 20309-20324/myPackage D/ACRA﹕ Sending request to https://mySite/myFolder/report.php
09-18 14:25:54.153 20309-20324/myPackage E/ACRA﹕ Failed to send crash report for 1411042794000-approved.stacktrace
org.acra.sender.ReportSenderException: Error while sending JSON report via Http POST
at org.acra.sender.HttpSender.send(HttpSender.java:228)
at org.acra.SendWorker.sendCrashReport(SendWorker.java:179)
at org.acra.SendWorker.checkAndSendReports(SendWorker.java:141)
at org.acra.SendWorker.run(SendWorker.java:77)
Caused by: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
at org.apache.harmony.xnet.provider.jsse.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:137)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:93)
at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:381)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509)
at org.acra.util.HttpRequest.send(HttpRequest.java:152)
at org.acra.sender.HttpSender.send(HttpSender.java:225)
            at org.acra.SendWorker.sendCrashReport(SendWorker.java:179)
            at org.acra.SendWorker.checkAndSendReports(SendWorker.java:141)
            at org.acra.SendWorker.run(SendWorker.java:77)
09-18 14:25:54.153 20309-20324/myPackage D/ACRA﹕ #checkAndSendReports - finish
How can I solve that problem?
Tanks!
The simple solution is to send via HTTP instead of HTTPS.
But I think the real issue is that you have not installed the SSL cert of your server correctly. It looks like it is missing some of it's intermediate certificates. See Android SSL - No Peer Certificate

Why does database initialization fail with "ERROR: improper qualified name (too many dotted names)"?

I'm using Scala 2.10 and Slick 2.10-1.0.1 with plain queries.
I tried to init a lazy evaluating database with Tomcat at localhost. For query evaluation I use PostgreSQL on port 5432.
As I tried to compile I got following error message:
ERROR org.quartz.core.JobRunShell - Job DEFAULT.MissionLifecycleManager threw an unhandled Exception: org.postgresql.util.PSQLException: ERROR: improper qualified name (too many dotted names)
Position: 16
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102) ~[postgresql-9.1-901.jdbc4.jar:na]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835) ~[postgresql-9.1-901.jdbc4.jar:na]
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257) ~[postgresql-9.1-901.jdbc4.jar:na]
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500) ~[postgresql-9.1-901.jdbc4.jar:na]
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388) ~[postgresql-9.1-901.jdbc4.jar:na]
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:381) ~[postgresql-9.1-901.jdbc4.jar:na]
at scala.slick.jdbc.StatementInvoker.results(StatementInvoker.scala:34) ~[slick_2.10-1.0.1.jar:1.0.1]
at scala.slick.jdbc.StatementInvoker.elementsTo(StatementInvoker.scala:17) ~[slick_2.10-1.0.1.jar:1.0.1]
....
This is the code of my initialisation:
import com.weiglewilczek.slf4s.Logging
import scala.slick.driver.PostgresDriver._
import scala.slick.session.Database
import Database.threadLocalSession
import scala.slick.jdbc.{GetResult, StaticQuery => Q}
import scala.slick.driver.PostgresDriver.simple._
object SQLUtilities extends Logging with ServiceInjector {
lazy val db = init()
private def init() = {
info("Connecting to postgres database at localhost") //writes in a log file
val qe = Database.forURL("jdbc:postgresql://localhost:5432", "user", "pass", driver = "org.postgresql.Driver")
info("Connected to database")
qe
}
}
Obviously, something went wrong. So I think, my database initiallisation is not correct. Do I have forgotten some parameters? Are my parameters correct at all?
An another - not so fatal - question: If I have a body where I want to log something at the beginning and at the end of a method - let's say always the same log message, but different bodys - as a sign that I started and leaved this method... Is there a proper way to do this than this example here in init()?
Specify a database in your connection string "jdbc:postgresql://localhost:5432/somedatabase".
See http://jdbc.postgresql.org/documentation/head/connect.html