0
내 안드로이드 응용 프로그램에서 구름 SQL에서 내 데이터베이스에 연결을 시도하고있어. 처음에는 데이터베이스와의 연결을 시도하고 쿼리에 대해 AsyncTask로 작업하려고합니다.안드로이드는 jdbc와 구글 클라우드 SQL에 연결
나는이 오류를 얻을 연결을 시도하는 동안 : 나는 mysql을 - connector.jar를 교체하려고
package com.example.user.trackyournevi.database;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class GoogleConnection {
private static final String TAG = "GoogleConnection";
private static GoogleConnection mInstance = null;
private Connection connection;
private String DRIVER_CLASS = "com.mysql.jdbc.Driver";
private String DB_NAME = "xxx";
private String DB_USER = "xxx";
private String DB_PASSWORD = "xxx";
private String DB_URL = String.format("jdbc://mysql://xxx.xxx.xxx.xxx:3306/");
public static synchronized GoogleConnection getsInstance() {
//Use the application context, which will insure that you don't
//accidentally leak on Activity's context
if(mInstance == null)
mInstance = new GoogleConnection();
return mInstance;
}
private GoogleConnection() {
initDBConnection();
}
private void initDBConnection() {
try {
Class.forName(DRIVER_CLASS);
this.connection = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
} catch (SQLException | ClassNotFoundException e){
//Log.e(TAG, "Can not connect to db");
e.printStackTrace();
System.exit(0);
}
}
하지만 누군가가 도움을 줄 수 있나요 을 작동하지 않습니다 :
java.sql.SQLException: No suitable driver
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err:
at java.sql.DriverManager.getConnection(DriverManager.java:186)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at java.sql.DriverManager.getConnection(DriverManager.java:213)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at com.example.user.trackyournevi.database.GoogleConnection.initDBConnection(GoogleConnection.java:46)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at com.example.user.trackyournevi.database.GoogleConnection.<init>(GoogleConnection.java:40)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at com.example.user.trackyournevi.database.GoogleConnection.getsInstance(GoogleConnection.java:35)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at com.example.user.trackyournevi.LoginActivity.onCreate(LoginActivity.java:86)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at android.app.Activity.performCreate(Activity.java:6876)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at android.app.ActivityThread.access$1100(ActivityThread.java:221)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at android.os.Looper.loop(Looper.java:158)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7224)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at java.lang.reflect.Method.invoke(Native Method)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
05-08 21:51:29.533 12626-12626/com.example.user.trackyournevi W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
내 코드입니다 나를? TNX
당신이 rigth 있습니다 ..하지만 –
을 스틸 작동하지 않는 문제가 지금 무엇인가? 내 최종 URL을 시도 했습니까? 'private String DB_URL = String.format ("jdbc : mysql : //xxx.xxx.xxx.xxx : 3306 /"+ DB_NAME);'두 개의 슬래시를 제거 했습니까? @DanaS –
다음 질문에 새로운 문제가 게시되었습니다 (오래되었습니다). –