Closed kopevgale closed 6 years ago
Hi kopevgale,
The tagged version number on the MySQL connector implementation is the tag of our latest release of the library, not your MySQL Server Version.
Our latest tag is 0.23 so if you change your implementation to be as follows it should be OK:
implementation 'com.github.BoardiesITSolutions:Android-MySQL-Connector:0.23'
.
Let me know how you get on and if you have any questions or issues then please let me know.
I just thought of something else. Although the tagged version number is wrong so my previous comment still applies but I think the error you are getting might be to do with your gradle version. Implementation is a fairly new thing in gradle, I think it was gradle 3 and it deprecated compile so it might be that you are using an older gradle version.
You can either upgrade your gradle version which would mean all of your imports would need to be changed from compile to implementation or change the import for the mysql connector to compile if you want to keep the current gradle version.
Hi boardy, how i can change the import for the mysql connector to compile if I want to keep the current gradle version?
Hi kopevgale, just changing the keyword implementation
to compile
should do the tick. So your gradle import line will be
compile 'com.github.BoardiesITSolutions:Android-MySQL-Connector:0.23
ok, now i doing this and take: `Failed to resolve: com.github.BoardiesITSolutions:Android-MySQL-Connector:0.23```
becoase mavenCentral () not adding?
Don't need mavenCentral, at least not for the connector library, so not sure why that would be the problem. Have you added the below to your gradle file, can't see it in your output. If so, can you let me know which gradle version you are using and I'll see if I can replicate the problem.
repositories {
maven { url 'https://jitpack.io' }
}
2.10 my gradle version yes, its adding:
repositories {
maven { url 'https://jitpack.io' }
}
Cheers. I'll see if I can replicate your problem using that gradle version.
I've not hit your exact problem but I've got to compile and run an app OK with your gradle version.
Below is my build.gradle (within your app/module folder)
apply plugin: 'android'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.BoardiesITSolutions.ConnectorPreGradleDebug"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
buildToolsVersion "27.0.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.1.1'
compile 'com.android.support.constraint:constraint-layout:1.1.2'
compile 'com.github.BoardiesITSolutions:Android-MySQL-Connector:0.23'
}
Below is the build.gradle in the top level directory of the project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The above isn't guaranteed to the best settings or versions. Android Studio really doesn't like downgrading gradle but the above gradle files sucessfully compiles and includes the MySQL connector library.
If possible I would recommend upgrading your gradle version though, version 2.x is quite old (currently on version 4.x) and it has a large number of improvements especially when it comes to performance and build times.
Let me know how you get on.
thank you very much, I will raise a gradle, as soon as I figure out how to do it. In the near future I'll let you know about the results
No worries.
If you want to upgrade gradle there's a gradle-wrapper.properties in the top level directory of your project /gradle/wrapper. You update the URL of the distribution URL to the latest version (currently 4.4). e.g. distributionURL will be distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
.
You'll then need to change all of your compile
to implementation
in your build.gradle dependencies and Android Studio usually sorts out the rest. Make sure you have a backup of your project though as it can go a little screwy at times.
Hi Kopevgale, Just wanted to check in to see if you managed to include and use the library OK. If so I'll close this issue, but please don't hesitate to get in touch if there's anything else I can help with.
all work, sanx!
That's great to hear, thanks for letting me know :)
Hey. Sorry for the impudence, but do you have any java code samples that mysql expressions are wrapped in.
I mean, do you have a skeleton or a template, how to wrap in a java code such expressions from mysql, as, for example,
CREATE DATABASE or USE DATABASE or CREATE TABLE TableName
Hi,
To change the default database, cannot use the command USE database
. You have to use the built in method on the connection object switchDatabase. This isn't a quirk of the Android MySQL Connector, this is the same as the normal MySQL Connector.
So to change the default database (equivalent to running USE database
) you can do the following:
mysqlConnection.switchDatabase("your_db_name", new IConnectionInterface() {
@Override
public void actionCompleted() {
//Database switched successfully
}
@Override
public void handleInvalidSQLPacketException(InvalidSQLPacketException e) {
errorHandler.handleInvalidSQLPacketException(e);
}
@Override
public void handleMySQLException(MySQLException e) {
errorHandler.handleMySQLException(e);
}
@Override
public void handleIOException(IOException e) {
errorHandler.handleIOException(e);
}
@Override
public void handleMySQLConnException(MySQLConnException e) {
errorHandler.handleMySQLConnException(e);
}
@Override
public void handleException(Exception e) {
errorHandler.handleGeneralException(e);
}
});
Create database and create tables is done in exactly the same way (same as with inserts, updates, deletes etc.
Statement statement = mysqlConnection.createStatement();
statement.execute("CREATE DATABASE my_new_db", new IConnectionInterface()
{
@Override
public void actionCompleted()
{
//action completed successfully
}
@Override
public void handleInvalidSQLPacketException(InvalidSQLPacketException e)
{
errorHandler.handleInvalidSQLPacketException(e);
}
@Override
public void handleMySQLException(MySQLException e)
{
errorHandler.handleMySQLException(e);
}
@Override
public void handleIOException(IOException e)
{
errorHandler.handleIOException(e);
}
@Override
public void handleMySQLConnException(MySQLConnException e)
{
errorHandler.handleMySQLConnException(e);
}
@Override
public void handleException(Exception e)
{
errorHandler.handleGeneralException(e);
}
});
If you're executing a query which returns a result set, e.g. SELECT, SHOW etc, its slightly different as instead of passing IConnectionInterface
instead you'll need to pass in IResultInterface
instead. as follows:
Statement statement = mysqlConnection.createStatement();
statement.executeQuery("SELECT * FROM my_table", new IResultInterface()
{
@Override
public void executionComplete(ResultSet resultSet)
{
addHistoryRecord(new QueryHistory(QueryHistory.Status.OK, txtQuery.getText().toString(), "Fetched " + resultSet.getNumRows() + " Row(s)", statement.getQueryTimeInMilliseconds()));
processResultset(resultSet);
}
@Override
public void handleInvalidSQLPacketException(InvalidSQLPacketException e)
{
Log.e("DBViewFragment", e.toString());
addHistoryRecord(new QueryHistory(QueryHistory.Status.ERROR, txtQuery.getText().toString(), e.toString(), statement.getQueryTimeInMilliseconds()));
errorHandler.handleInvalidSQLPacketException(e);
}
@Override
public void handleMySQLException(MySQLException e)
{
Log.e("DBViewFragement", e.toString());
addHistoryRecord(new QueryHistory(QueryHistory.Status.ERROR, txtQuery.getText().toString(), e.toString(), statement.getQueryTimeInMilliseconds()));
errorHandler.handleMySQLException(e);
}
@Override
public void handleIOException(IOException e)
{
Log.e("DBViewFragement",e.toString());
addHistoryRecord(new QueryHistory(QueryHistory.Status.ERROR, txtQuery.getText().toString(), e.toString(), statement.getQueryTimeInMilliseconds()));
errorHandler.handleIOException(e);
}
@Override
public void handleMySQLConnException(MySQLConnException e)
{
Log.e("DBViewFragement", e.toString());
addHistoryRecord(new QueryHistory(QueryHistory.Status.ERROR, txtQuery.getText().toString(), e.toString(), statement.getQueryTimeInMilliseconds()));
errorHandler.handleMySQLConnException(e);
}
@Override
public void handleException(Exception e)
{
Log.e("DBViewFragement", e.toString());
addHistoryRecord(new QueryHistory(QueryHistory.Status.ERROR, txtQuery.getText().toString(), e.toString(), statement.getQueryTimeInMilliseconds()));
errorHandler.handleGeneralException(e);
}
});
mysqlConnection
is your connection object.
Hope this helps
You will perfectly explain, in the following days I will test and configure your solution. Thank you very much!
No problem glad to help, I've also added the examples above in the README file in the master branch.
Hi, when i Adding Dependency, i take in build log in Android Studio:
Could not find method implementation() for arguments [com.github.BoardiesITSolutions:Android-MySQL-Connector:5.7.22] on project ':app'.
it is my build.gradle file: `apply plugin: 'com.android.application'android { compileSdkVersion 24 buildToolsVersion "24.0.0"
}
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12'
// MariaDB 10.1.31 implementation 'com.github.BoardiesITSolutions:Android-MySQL-Connector:5.7.22' // include 'com.github.BoardiesITSolutions:Android-MySQL-Connector:10.1.31' // compile 'com.github.BoardiesITSolutions:Android-MySQL-Connector:10.1.31'
}`