Xampp: DB connection for Android (Java) without PHP

José
3 min readJul 28, 2020

--

Download and install Xampp from their official page
In this example I use this version: 7.4.5

Xampp set-up has a list of components that you can install too. We’re going to check the Apache and MySQL for this example, you can uncheck those which you don’t

Then select an installation folder. I use the default one

Once you had been installed Xampp control, you must start the services Apache and mySQL

If Apache don’t start because of a localhost connection error, we’re going to change the file httpd-xampp.conf located at: (by default in this folder)

C:\xampp\apache\conf\extra

Change those lines for the following and save the file.

Alias /phpmyadmin “C:/xampp/phpMyAdmin/”
<Directory “C:/xampp/phpMyAdmin”>
AllowOverride AuthConfig
Order deny,allow
Allow from all
Require all granted
</Directory>
Localhost connection error. Change settings on this file httpd-xampp.conf
Localhost connection error. Change settings on this file httpd-xampp.conf

Restart apache from Xampp app. By now your PC will work as a server, that’s because of Apache’s services.

“localhost (127.0.0.1)” works only on your PC, so if we want to connect other devices, as our phone, to our “PC server” we have to get our IP address. For that, click on Windows and type “CMD” to open the command prompt

Execute this command: ipconfig

I going to use this “IPv4 Address (192.166.1.5)”
I going to use this “IPv4 Address (192.166.1.5)”

Once Apache and mySQL are working, we could check on browser our db is up to use

 ╔═══════════════════════════════╦═══════════════════════════════╗
║ Server ║ IP ║
╠═══════════════════════════════╬═══════════════════════════════╣
║ localhost (127.0.0.1) ║ http://localhost/phpmyadmin
║ Pc ip (this example that url) ║ http://192.166.1.5/phpmyadmin
╚═══════════════════════════════╩═══════════════════════════════╝
Another device could connect to our pc server (Apache instance)

Our server is ready, we need to check our database settings. We use a JDBC user for our connection, and this must have some privileges on database, so we’ll have to execute this query to assign them.

We can execute this query/script on phpmyadmin webpage or in an external app like MySQL Workbench

GRANT ALL PRIVILEGES ON `db_nameOfYourDB`.* TO ‘root’@’%’ WITH GRANT OPTION;

My user is called “root” and I run the script on MySQL Workbench and checked it on phpmyadmin webpage

Another way to check DB server is running is going to: Server > Server Status > Running

Java class to connect to our DB

Requirements

  • You must have your DB Script to create it

For MySQL settings you need the JDBC driver and plugins for your PC to build your app releases
You must have installed the connectors and JDBC on your app’s projects. For Android you could use this sentence on your build.gradle file

implementation group: ‘mysql’, name: ‘mysql-connector-java’, version: ‘5.1.47’

MySQL tools versions from MySQLInstaller.exe

You could ask me any questions you have

Hope this can help you!

--

--