My question is how to connect android with java,and Mysql? I am doing a project on android where i need to save the data given by the user in database. can anyone help me in this?
I would generally expect JDBC to work on Android against MySQL. I am sure you can find plenty of good examples there and make it work if this is really what you want. However there are a few things you want to make sure of before you go this route:
Is your app connecting directly to a database server?
Is that expected to be available through a firewall?
Are you sure you won't need something like connection pooling?
I could imagine cases where one might want to connect directly to a database server from Android but these are niche cases. Make sure it is what you want to do and then use the relevant JDBC driver if it is.
Related
I am developing a game for Android using LibGDX and a key requirement of this project is to be able to store and query data in a database. I need a database for several reasons; one main reason being the need to store user details when they sign up and validate them when they log in. I also need the database to store dateandtime stamps, game stats, e.t.c.
I was thinking of using SQLite to implement this and I have already designed the relational database, however, I cannot find a feasible solution to doing so on LibGDX. I have seen forums and posts mentioning the use of interfacing, however, I have researched and tried doing this method for far too long now and to no avail. I have read this article - https://code.google.com/archive/p/libgdx-users/wikis/SQLite.wiki but it doesn't help at all. I have also seen a few third-party extensions for enabling the use of SQLite databases.
This is the link to one I attempted to use which uses interfacing - https://github.com/Inexsoft/libgdx-database-extension
This is the link to one I attempted to use which gives several project files in order to somehow enable the use of a database with LibGDX - https://github.com/Inexsoft/libgdx-database-extension
I am able to implement an interface for Native Functions on a basic level such as opening a website - also from another post I saw on here (Using SQLite from libGDX on Android). However, I have no idea as to how I can develop that example any further to accommodate the use of a database. Please note that I am willing to explore other options in order to store this data, however, it really needs to be in a relational database form due to the nature of my project requirements. It does not have to use SQLite, if there are better alternatives out there.
Any help will be greatly appreciated as I have no other resort left and the project deadline is fast approaching.
I've been searching on how to add a barcode scanner to my Java Project using my phone by connecting my software and scan the code using zxing app. Does anybody know of any examples or know how to do this easily? Any help is greatly appreciated.
Seems like you want to your database keep alive every time.I see two option there.
One Option
You have to keep on the computer where your wamp server run. Just like regular server. never stop keep running. This solution is some kind of stupid but its works for your problem.
Two Option
This is the best option. Configure your database in the hosting service. There are lot of free servers available.
Ex https://www.000webhost.com one of the free hosting services.
You can create free database instance using this service and map your db configuration details in your software.(host_url, username, password etc.)
you can keep on your db for ever.
Hard to understand what are you looking for but i think this will help you.
fellow stackers. I'm using android studios. As the title indicates; I've managed to get JDBC to work in java, but not on android. I made a class dedicated for everything database related. Both my Java code and my android code are in the same folder and have the EXACT same code.
A function in my database class returns an ArrayList of results, fetching this list works perfectly fine in java, but in android, it returns null, which results in a NullPointerException.
I've done some research on the matter and I am using the INTERNET persmission as well as calling the database class from an async class.
Any suggestions?
Edit: My database is hosted on a webserver.
Thanks, everyone, for your help - I've discovered the root of the issue. In the try/catch, I returned null instead of logging the error when caught. The issue lies in the driver: "java.sql.SQLException: No suitable driver". I ought to be able to take it from here.
It works in Java because you're most likely connected to a database in your very own machine (I'm guessing you're trying to access localhost).
In Android, it doesn't work that way. Localhost in android would be your smartphone and you probably don't have any database in it.
My suggestion: create some sort of webservice that connects to your database and returns the results to your android application. It acts as a bridge between your DB and your app.
Now, I have some problems here:
I looked several times in Google and so on, but I can't find an "easy" way to get this done. And currently having a migraine... not helping me... though
I have a java eclipse program (Swing application to be a "controller" for production-machines).
I need to design an Android app, which needs to take data from the eclipse program in a wireless network (and also send them back).
Just found solutions like JPARSON or setting up a real server, but that is way too complicated... i donĀ“t need?! (or want :D ) to set up a whole website with php or something...
Can someone of you help me out with a better solution? It doesn't need to be code-specific, I just want to exchange like 10 strings for these machines.
If you want to exchange data you need a communication medium. The easiest way to do this is via TCP/IP protocol suite. If you decide on having a Server-Client architecture, your serwer has to listen for what phones have to say. He can do this by listening on specified port and you would have to handle "protocol", or you can use somewhat easier approach which is to write php script, or Java Servlet. PHP script is easier becaouse there is like a gazzilion php hosting providers and it's cheap. If you would like to write your own serwer, you wold need some sort of Virtual Private Server, and deploy your app there. Plus it would be helpfull if you explained a little more your environment and what you are trying to achive.
There's built in httpserver http://docs.oracle.com/javase/6/docs/jre/api/net/httpserver/spec/index.html so you can easily implement a simple webservice in standalone java. Then just use URLConnection from android to post/get data, probably in json or your own format.
I'm starting a new project. It consists of:
Java desktop application downloadable from the internet with a client database.
PHP website on the internet with a server database.
The user who downloaded the app will use it to add items (not important what are they now) to the local database offline. When/If he is online, the item will be added to the server database so other connected users (through the desktop app or through the website) will see it.
I googled the issue and found it's more complected than I guess. One of the solution is to use some ready tools like SymmetricDS and Daffodil to gain in term of security, performance and scalability, but they're difficult to configure and install in both client and server side, and need the access to command prompt which requires me to pass to a dedicated host (well, that is not a real problem). Also, all what I want is just what I've described, not all what these tools actually provide.
Can I achieve that by myself within my Java application and maybe with the help of
the web server PHP?
I'm using MySQL for the info.
Edit: what really matters is to send items to the server database. Reading it can be less tricky using RSS Feed reading, for example.
Basically, you can use HTTP/HTTPS API. When a user online, send items to your php file and mark the items "sended" at local database. But you have to control edited or deleted statuses. So, yes that is much complicated but a solution.
Well the easiest solution that comes to my mind would be to save for each item a last edit date (on the server as well as on the client). Additionaly you have to keep track when a client got his last update from the server.
So whenever a client goes online the server sends him all updates.
But for that you have to make sure that the time on the client and the server are the same, and it doesn't solve the problem what happens if two clients edit the same item.
CouchDB solves the distributed synchronization problem very nicely, but it is a NoSQL DB. Depending on what your application should do, using it would boil down to using instances of CouchDB both locally inside very application, and on the central server.
You'd have to deal with conflicts nevertheless. The only thing CouchDB will support you with is easier detection of conflicts, and the data of both conflicting edits, so your application can work it out either automatically, or with user help.
On the other hand, generatin a unique id on the central server can be as easy as adding the creating user's id to each item id.