I have a Linux server which has a Database. I want to query the Database from my Android application.
All the tutorials I find tell me to use PHP for some reason.
Can't I just query like I would normally with a Java application? Which is, I connect to the Database then send my queries as Strings.
It seems I need something like this:
Why?
PHP is just a server-side programming language. You can use any language and any server. The main issue is
Can I Query MySQL Database Directly from Android without a Web Service?
Yes you can. Just open the port where your MySql database is set usually at 3306. You also need JDBC Driver to set up connection to it.
Should I Query MySQL Database Directly from Android without a Web Service?
Unless you want to make a Database Client app (like phpMyAdmin) where each user holds his own credentials then you should not. In such case everyone will be using their own credentials to access their own db. In your case, you'd be hardcoding your database credentials in the app for everyone to access.
Well, your database user is only allowed to connect from localhost not from the outer world. If you want to execute queries from outer world then you will have to allow access from all IPs i.e. You will have to create a user create user 'app'#'%' identified by password123 (In my opinion it will be a bad approach).
Moreover you can build REST Web Services either using PHP (Recommended) or JAVA to interact with the database without opening it to world wide.
Related
I am developing a Java based desktop application for a school.
As I am beginner, I am facing some issues.
Where to store the data of students or teachers (In files or database )
If in files, how I will ensure the security ?
If in Database, Can I embed db in application or I need to install db on server.
If db is installed on server, how I will manage the application if I will give that to other school users. (Means distributing the application to different users)
Do I need to create separate database for different users on servers or Can I make separate schema on same db.
First of all you need Mysql server installed for the following:
1->Store it in Database(mysql database)
2->database security (refer mysql secuity)
3->all you need is mysql connector for java put in the application folder of app you are creating
4->You can provide database inside of folder of application no
5->You can add user in same database.
You could do this:
1.Where to store the data of students or teachers (In files or database )
If you would like to go with open source databases, go with MYSQL instead of storing in files. Basic user authentication is enough to give you security to get started with your application. So no need of 2nd.
You can install and run on a remote system or your local machine depending on your application requirements and budgets.
On top your database, to communicate with it, develop a Spring web application (Spring data jpa) with REST web services so that any user can communicate with your application.
In your data base, you can manage users as well with basic authentication like username, password.
No you need not create separate schemas or dbs for each user. Instead you can create a single table that has information regarding Users for your application. For example, create a table "User_Management" which has columns like emailId, phone, name etc.
To get started, you can refer below:
http://javabeat.net/spring-data-jpa/
You should use Database (the best for this is Derby DB default for Java)
You can Embed Derby DB in application and also use this as server client.
Derby DB is light weight 2MB.
Alternatively you can use MySQL
If db is installed on server, You would create server on other school's PC or
you have to purchase the online server.
The Best as I described is Derby but if you want to use other you can use Xampp , Wampp server for local server client applications.
I have developed a REST web-service in Java interacting with a MySQL database.I want to deploy the web-service and the create a database at a server so that I can invoke it from an application.I tried Microsoft Azure but was unable to get it done.Where can I find relevant information for this?
I had similar problems with a MySQL database using the third party option in the Azure Marketplace from ClearDb. What I ended up doing was switching my database from a MySQL instance to an Azure Database Instance (Subset of SQL Server's features.) This worked perfectly for me! I was able to query from my database feed data to my api, and access the API through my Azure Web App.
I understand this may not be an option for you, however, Digital Ocean is a great cloud hosting option (with scaling similar to Azure, although not as good in my honest opinion.) You can set up a Linux Environment with a MySQL Server and JVM and serve your whole API through there. Best of Luck!
#coderden, According to your description, I think you have been deployed your Java Application on an Azure WebApp. Then when you created a MySQL database on Azure for connection from the Java webapp, please make sure the webapp & mysql instance created in a same resource group and note the connection string of MySQL on Azure.
As reference, please see the article to try again although it's for PHP, the steps are the same for Java.
When I want to create an SQLite external database for android application, do I have to have a server with database that is always running?
Yes, since it will be on a server. If the server isn't running, then your application won't be able to get any data from the database.
There's a very important distinction that we're missing here - what it means to have a remote database.
SQLite is a flat-file embedded database engine. You don't have a separate process running SQLite in the background like you would one for MySQL or PostgreSQL or Oracle, nor would you really want to - SQLite as a database is pretty limited in what it can do.
If you say that you're going to have a remote SQLite database, then that implies that you have some server somewhere that writes to and reads from this flat-file database. If you can finagle that somehow, and make it secure, then more power to you - and yes, you could have this accessible remotely for your intents and purposes. Trust me though, you wouldn't want to.
What you're likely looking for is a way to remotely run MySQL or PostgreSQL instead, as these are proper database management systems (DBMS) which will be able to both service remote connections and give you a more expanded set of the SQL language.
Ultimately though, the database server must be running at all times. You wouldn't be able to connect to the database if it's down, and you don't know the lifespan of the app (or when it's going to be accessed, etc).
i got the below information from SQLite home page
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
Based on the above statement you don't any server. I hope this information is useful to you.
Scenario:
We have a PHP/MySQL based corporate web portal and a separate MS SQL database on a remote server which could be accesed by a 3rd party vendor Java application(web client communicating with the MSSQL database).
Requirement:
I would like to get rid of that Java application and transfer all functionalities to the PHP web portal and I need to figure out the queries as I don't have the source code of that Java application and there is no way to reach the vendor to ask.
Is there any way I can capture the queries that Java application is sending so I can use those in my PHP scripts?
Maybe tracing last queries from MSSQL somehow? Or
Somehow see what the Java application emits to the database in some way?
While you can log incoming queries coming into the server (How to see query history in SQL Server Management Studio) you are still going to rewrite most of the queries as I'm sure most of them will be dynamic. You will simply see the end result in the log like this:
select * from users where id=5
While in the php code it will be a mysqli or pdo function that binds the 5 value to a prepared statement. So you will have to figure out why or how the java application came up with the query it did.
I have my website(in php) running in Yahoo small business and Application(in java) in Rackspace.com.both server has got mysql database.
I want to query my application database(in rackspace) from my website(in Yahoo) and get the result set.
How to do it?
Please suggest me reference document to do it.
Is it a good idea to directly query a remote database ? means is there any performance issue will rise ?
It's always a bad idea to remotely access data that do not "belong" to your app. In this case, the PHP app should access a set of functions that are exposed on the Java side. This is to make sure that when you upgrade the Java side, you may change the schema of the database without affecting anyone interacting with it.
I recommend you look into Web Services -- there are many methods (eg look for RPC, REST, SOAP), and some might be a better fit for your needs than others.
If you open the database port, it should be easy but unsecure.
If you can access the database port in a secure manner (for example vpn tunnel), it would be easy and secure :)
My suggestion would be to implement the querys as SOAP Services in the Application and access them via PHP. Google should provide enough Results about SOAP in both languages.
AFAIK
if you would like to use the java function from php you should implement the web services in java in any of the web service types
You can access web services from php using the cURL calls