This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Production-Ready Serverless (Operational Best Practices) and have Yan Cui on-line!
See this thread for details.
Win a copy of Production-Ready Serverless (Operational Best Practices) this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Connect to a SQL online database on Android Studio  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Would anyone know any good tutorials (or have their own code) that I could follow to connect my SQL database to Android Studio.

I simply just want to log in a User.

I've been struggling to get this working for quite a while now.

Any help would be much appreciated.

Thanks.
 
Saloon Keeper
Posts: 5326
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you have so far? The usual approach would be to connect via a REST web service running on your web server.
 
Harry Burke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:What do you have so far? The usual approach would be to connect via a REST web service running on your web server.



I'm currently getting an error on Build in the Run Tasks --> :app:transformClassesWithInstantRunForDebug

 
Tim Moores
Saloon Keeper
Posts: 5326
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

com/sun/net/ssl/X509TrustManager


That looks like an Sun/Oracle-specific class that I'm not sure if it's available on Android. What library or piece of code needs that?
 
Harry Burke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:
That looks like an Sun/Oracle-specific class that I'm not sure if it's available on Android. What library or piece of code needs that?



I really don't know Tim, I just found the source code and tried to swap in my database details.

Apologies
 
Tim Moores
Saloon Keeper
Posts: 5326
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see why a class named TrustManager -that is not already part of Android- should be required for making a DB connection. How are you making that connection? What kind of source code is that you found?
 
Harry Burke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya I understand it must have been a bad example I chose.

Would you be able to suggest any source code that I could use to get the database set up on the app?

I appreciate your help!
 
Tim Moores
Saloon Keeper
Posts: 5326
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, how are you trying to establish a DB connection? As I said, my preferred approach (and indeed the most commonly used one) would be via a web service, possibly exchanging JSON data.

It may be possible to use a JDBC driver directly, but you're likely to run into issues with closed ports on your firewall, and need to make sure you're using an encrypted connection (which is not always the default).

What DB are you using in the backend?
 
Harry Burke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I first began trying to get the database connected, I tried using JSON but got very confused because I've little knowledge of it so it was very frustrating.

However, maybe I was doing it totally wrong and would really appreciate it if you could suggest some source code if you can.

I'm using SQL database and accessing it through phpMyAdmin.

Thanks.
 
Bartender
Posts: 20557
120
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we need some clarifications here.

First, Android Studio is the IDE. It's not part of the Android app. The only reason you'd have for the IDE to be connecting to a database is if you wanted to run SQL queries and commands as an IDE user. That is, as a "database explorer".

The app is a different matter. Android has a built-in database: SQLite. The API for that is well-documented.

As far as talking to external databases goes, that's a different matter. The standard for that is to use a JDBC driver. However, you have 2 problems there:

1. No database should be opening ports on the open Internet. That's what precipitated the infamous SQL Slammer debacle. So the only safe place to connect a mobile directly to a database is on an in-house LAN/WiFi network.

2. You cannot take just any old Java JAR and import it into Android. Dalvik may look a lot like Java, but in the end, it isn't Java. Dalvik doesn't have the complete set of classes that the standard JRE does, and even in classes that it does mirror from Java may not contain the full set of methods that actual Java does. And since the way you use JDBC is to make a driver JAR available to the application failure can be expected.

In practical terms, your best bet is generally to setup a web application with a ReST interface and have the Android app make ReST calls to it, so that the actual database interactions are done on the server, not in the mobile device. That way you don't need additional driver code in the mobile device and the amount of potential mayhen hackers can do is limited to what you allow through the ReST interface.

The ReST server can be in any language. I like NodeJS, but PHP, Python, even Enterprise Java are all suitable.
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!