I cannot connect to my database thru Compute Engine.
Things I have done so far:
Setup my Compute Engine
Connect my Compute Engine to my Cloud SQL
Install and run Cloud Proxy on my Compute Engine
Included the JDBC Jar file on my libs folder
Created the JDBC Connection string
"jdbc:mysql:///?cloudSqlInstance=&socketFactory=com.google.cloud.sql.mysql.SocketFactory;user=&password=";
Added dependency on my Gradle file
-implementation fileTree(dir: 'libs', include: ['*.jar'])
-implementation 'com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.1.0'
Here is the stack trace:
W/System.err: java.sql.SQLNonTransientConnectionException: Cannot
connect to MySQL server on localhost:3,306. W/System.err: Make sure
that there is a MySQL server running on the machine/port you are
trying to connect to and that the machine this software is running on
is able to connect to this host/port (i.e. not firewalled). Also make
sure that the server has not been started with the --skip-networking
flag.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
W/System.err: at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:470)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
W/System.err: at
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
at java.sql.DriverManager.getConnection(DriverManager.java:237)
W/System.err: at
com.dedase.dedaseconstruction.ui.login.LoginActivity$GetPatientID.doInBackground(LoginActivity.java:150)
at com.dedase.dedaseconstruction.ui.login.LoginActivity$GetPatientID.doInBackground(LoginActivity.java:136)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
W/System.err: at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.mysql.cj.protocol.SocketConnection
com.mysql.cj.protocol.a.NativeProtocol.getSocketConnection()' on a
null object reference
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:980)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
W/System.err: at
com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:456)
... 12 more I/Choreographer: Skipped 58 frames! The application may be doing too much work on its main thread. I/zygote: Do full code
cache collection, code=123KB, data=111KB
After code cache collection, code=117KB, data=78KB
This line localhost:3,306. looks really suspicious. Are you sure you don't have a typo somewhere?
You probably came across this repo, and it's not very accurate. I don't have a java client at hand to test it, but I do use Cloud SQL with a different stack and the point of using Proxy is that your app connects to the DB via it as if the DB itself is running locally. Your connection string should not have anything apart from creds and localhost:3306.
Related
Firebase realtime database is no longer loading in my console. It only show an empty content without any error. Rules for the database fail to load as well.
Inside my Android app writes to the realtime database fail with :
E/SOL: failed to put
'https://[appid].firebaseio.com/logs/2022/3/12/0/us_0600830214/s110.json',
ex: Failed to connect to
[appid].firebaseio.com/2600:1901:0:94b6:::443
java.net.ConnectException: Failed to connect to
[appid].firebaseio.com/2600:1901:0:94b6:::443
atokhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:297)
atokhttp3.internal.connection.RealConnection.connect(RealConnection.kt:207)
atokhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
atokhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
atokhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
atokhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
atokhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
atokhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
atokhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
atokhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
atokhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
atokhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
atokhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
atokhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
atokhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
atokhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
Suppressed: java.net.SocketTimeoutException: failed to connect
to [appid].firebaseio.com/35.201.97.85 (port 443) from
/10.0.2.16 (port 33500) after 10000ms
at libcore.io.IoBridge.connectErrno(IoBridge.java:191)
at libcore.io.IoBridge.connect(IoBridge.java:135)
at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:142)
atjava.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
atjava.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
atjava.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
at java.net.Socket.connect(Socket.java:621)
atokhttp3.internal.platform.Platform.connectSocket(Platform.kt:120)
atokhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:295)
I changed nothing in my code or console. A couple of days ago the console stop loading and the write errors I think stop working way before I just didn't pay much attention to it.
I don't see any project quotas being surpassed, all values are very close to 0% of usage for the free spark plan.
I also checked the google-services.json, minor changes, ... and updating to the new version did not fix the write failures.
Has anyone else experienced this?
I have contacted Firebase support and they have confirmed that such behavior have been reported by several other users but from what they can tell it is all fine on their side. The issue lies with the ISP from my country. All other reports had the same origin.
I am trying to connect to mysql using wampp and the following error is thrown how to solve this?
W/System.err: java.io.FileNotFoundException: http://192.168.2.198/login.php
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:250)
at com.example.mysqltest.BackgroundWorker.doInBackground(BackgroundWorker.java:46)
at com.example.mysqltest.BackgroundWorker.doInBackground(BackgroundWorker.java:19)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
There are following possibility to occur this issue
maybe your project or file location is not perfect
maybe because of the port number or IP not match time of calling
First, try to run this page in your mobile browser web browser and it will work in mobile browser then it will work in API definitely if not work then you need to change in your config
anybody knows how to connect MYSQL to android studio using MYSQL workbench. I have tried all methods, it shows following error.
com.mysql.jdbc.CommunicationsException: Communications link failure due to
underlying exception:
01-17 16:21:56.845 30367-30442/animaltracking.kevell.com.myapplication
W/System.err: ** BEGIN NESTED EXCEPTION **
01-17 16:21:56.845 30367-30442/animaltracking.kevell.com.myapplication
W/System.err: java.net.SocketException
01-17 16:21:56.845 30367-30442/animaltracking.kevell.com.myapplication
W/System.err: MESSAGE: java.net.ConnectException: Connection refused
You can use the following link to connect third-party database By using rest web services or web services:-
Link:-https://www.youtube.com/watch?v=Ucs-blvF3d8&t=1096s
NOTE:- Use Volley or Volley plus, Retrofit, HttpOk
You should not do this. Instead you should use REST APIs to communicate with database.
https://android.jlelse.eu/consuming-rest-api-using-retrofit-library-in-android-ed47aef01ecb
I've just learnt and implemented my first Meteor app with simple meteor create hellometeor command, then have used ngrok to make localhost:3000 port live.
Then I have used delight-im/Android-DDP library to connect to the direct ws url as per the following code:
// create a new instance, where mMeteor is a global var.
mMeteor = new Meteor(this, "ws://180a3c0e.ngrok.io", new InMemoryDatabase()); // "ws://180a3c0e.ngrok.io" is the temp. url after tunneling `localhost:3000`
// register the callback that will handle events and receive messages
mMeteor.addCallback(this); // as the activity implements MeteorCallback
// establish the connection
mMeteor.connect();
But every-time I try to run this code, I'm getting the following error, for which I've found no suggestion or straight-forward solution, for a newbie like me in Meteor like platforms during the past 6hrs of googling and reading:
W/System.err: java.lang.Exception: com.neovisionaries.ws.client.OpeningHandshakeException: The status code of the opening handshake response is not '101 Switching Protocols'. The status line is: HTTP/1.0 502 Bad Gateway
W/System.err: at im.delight.android.ddp.Meteor$1.onError(Meteor.java:195)
W/System.err: at com.neovisionaries.ws.client.ListenerManager.callOnError(ListenerManager.java:432)
W/System.err: at com.neovisionaries.ws.client.ConnectThread.handleError(ConnectThread.java:50)
W/System.err: at com.neovisionaries.ws.client.ConnectThread.run(ConnectThread.java:41)
W/System.err: Caused by: com.neovisionaries.ws.client.OpeningHandshakeException: The status code of the opening handshake response is not '101 Switching Protocols'. The status line is: HTTP/1.0 502 Bad Gateway
W/System.err: at com.neovisionaries.ws.client.HandshakeReader.validateStatusLine(HandshakeReader.java:232)
W/System.err: at com.neovisionaries.ws.client.HandshakeReader.readHandshake(HandshakeReader.java:54)
W/System.err: at com.neovisionaries.ws.client.WebSocket.readHandshake(WebSocket.java:3113)
W/System.err: at com.neovisionaries.ws.client.WebSocket.shakeHands(WebSocket.java:2992)
W/System.err: at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:2034)
W/System.err: at com.neovisionaries.ws.client.ConnectThread.run(ConnectThread.java:37)
May be I'm missing a very common thing in the Meteor server-side, as I haven't code a single line in it, other than initiating the project.Please enlighten me in this regard.
TIA.
I should be crucified for not knowing that Meteor has its websocket connection at ws://.../websocket url.
I have just added /websocket at the end of the previous URL and everything is working just as smooth.
I'm having trouble with reaching my Google Cloud Endpoints backend from my Android application. I use the following related tools and libraries:
Android Studio 2.3
Gradle plugin - com.google.appengine:gradle-appengine-plugin:1.9.49
App Engine SDK - com.google.appengine:appengine-java-sdk:1.9.49
Endpoints library - com.google.appengine:appengine-endpoints:1.9.49
Endpoints dependencies - com.google.appengine:appengine-endpoints-deps:1.9.49
I've followed the documentation on testing with a physical device against the local development server, which means I've added the line httpAddress = "0.0.0.0" to the build.gradle in the backend module, and I connect to the backend using the following code:
SomeApi.Builder builder = new SomeApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null);
builder.setApplicationName("someapplicationname");
builder.setRootUrl("http://192.168.1.1:8080/_ah/api/");
builder.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer()
{
#Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException
{
abstractGoogleClientRequest.setDisableGZipContent(true);
}
});
SomeApi api = builder.build();
I then call a method of the created api using the following line:
api.someMethod("Some random string").execute();
And this is where the problem occurs. This method call triggers the following exception pointing to the same method call (the line above):
W/System.err: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
W/System.err: at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
W/System.err: at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
W/System.err: at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
W/System.err: at se.essvagsystemab.mobiltdispenssystem.licensemanager.simple.fragment.MainFragment$13.doInBackground(MainFragment.java:381)
W/System.err: at se.essvagsystemab.mobiltdispenssystem.licensemanager.simple.fragment.MainFragment$13.doInBackground(MainFragment.java:373)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:304)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W/System.err: at java.lang.Thread.run(Thread.java:761)
The strange thing is that the requests doesn't even reach the endpoint. The exception seems to be thrown by the Endpoints library on the client side, because the the server log does not show any signs of error, it contains the log messages printed when starting the server, and that's it.
I have no idea what is causing this, so any help is greatly appreciated!
Turns out that I copied the wrong IP-address from the ipconfig-output, even though I mentioned I'm using the correct IP-address. Hrrm, embarassing...
After trying (what felt like) every possible solution, I once again checked the IP, and it turned out I'd copied the one labeled Default Gateway, which was obviously not as correct as the one labeled IPv4 Address!
So, if you're experiencing the same problem but still you feel like you've done everything correctly, make sure to double check the IP before giving up!