I've been searching and can't find an answer anywhere. I also haven't had time to try it out either.
Is it possible, using java in the Google App Engine (GAE), to connect to a remote database. Whether it MySql, SQLServer, etc. Will it be allowed to make calls outside of it's domain? Is it possible to even use the required libraries to make such a connection?
The closest thing that you will find is the Google Secure Data Connector. All connections outbound from GAE are HTTP based, so you're very unlikely to get a jdbc type connection to a database server (MySql, SqlServer, etc).
IMHO you can try to tunnel JDBC through HTTP. It is possible. For example here is free solution http://sourceforge.net/projects/sqlgateway/ and here commercial http://www.idssoftware.com/jdbcdrv.html :)
I do this all the time using a REST API on the server that contains the database. Depending on your needs (eg, do you need ad-hoc queries) you may want to choose a REST API with some flexibility.
There are quite a few simple REST-DB libraries around, such as http://phprestsql.sourceforge.net/
Though you may want to simply roll your own using http://www.playframework.org/ or http://guides.rubyonrails.org/getting_started.html#rest
Dont use HTTP for DB connections as it is less secure.
Use CLoud SQL instead (jdbc type connection, mysql like queries and drivers in jars)
getting started with cloud sql
an easy video for java + cloud sql + app engine
Related
I am trying to connect from eclipse to cloud sql using app engine server, In SQL authorization I have added my ip address and given #anyhost access. I am using jdbc socketfactory to connect to cloud sql. But I am getting the below exception
please refer this link(exception screenshot)
Please provide error messages as actual text, not images. This makes searching for anything difficult. You also have your instance connection string in the image. I advise you to remove this.
As for answering your question, without more information I can give you a generalized answer.
When connecting from App Engine, you do not need to whitelist any IPs. Whitelisting IPs doesn't actually work with GAE as the IPs may change for new instances.
GAE instances have the Cloud SQL proxy running and you specify the connection details in your pom.xml.
Which exact connection method you need to use depends on your JAVA version, whether you're using GAE Standard or GAE Flexible, and if you're using a 1st or 2nd generation Cloud SQL instance.
This page provides links to details for all of the different scenarios to connect from GAE to Cloud SQL. For local testing of your app, you will have to have the Cloud SQL proxy running locally. This quickstart shows how to set this up.
I am working on a project where the raspberry pi (model B) runs JAVA application to connect to and retrieve data from a Router.
What i want to know is the best approach or the best database that i should use to store that data retrieved from the router. Knowing that i will need to build another android application that should connect to that database (on the raspberry pi) and display that data.
So, what database that is compatible with the java application and the android application?
Also, later on i wish i could run the RPI as a server that enables me to connect to that database from anywhere.
Keeping in mind that:
I am new to Raspberry pi
New to Database
I suggest you to take a look at OrientDb is a NoSql Java graph-document db (you can chose) it support a lot of queries paradigm and an Sql dialect as well (you dont have the join), is fast, light, and support native rest query, i have tested it on raspberry pi (even in distributed multi-master mode on 2/3 raspberry node) and it perform well, the nice thing is that allow you to think in a different way, your data is presented like a java object an exposed you by rest paradigm in Json over http so you can think your client application on client side, using html 5 and jscript framework like angularJs for example (and you can 'deploy' your static resource direcly on the db that work like an extremly light application server)
This answer follows the previous comments. Let's say :
You have your router. Connected to it you have PC (with IP address called IP1) and your RPI with IP2.
On your RPI, I guess you have RaspBian. So with the package manager, you install mysql. You create your desired database and tables.
When using eclipse to access your database for testing purpose, or explore all data, I think you need to provide the jdbc driver, and configure the url of the db. Because you are running eclipse on your pc and you want to access the db hosted by the RPI, you should provide the IP2 address in the url.
Because your Java app will run on RPI, you can set the url to "localhost". See the following link : http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html
So, to sum up, eclipse and java app both need a mysql jdbc driver, configured the right way.
Later, you'll want to access your db through your android app. You'll need to configure your router with port forwarding, to access your db from outside. But this is out of topic. I let you search.
Almost All the Databases are Compatible with JAVA.And Hardly I belive that you will not have such privilege to choose Database while develop real time Application .
Java and Android Both are not different , both are same on a Pillar.There will be no problem because of using Database.
i suggest SQLite as Android uses it natively and it does not need that much of resources as other DBMS like *SQL
I have a desktop application and it makes use of JDBC. I have no problem with JDBC whenever I use localhost. Now, I am to connect to a server that does not allow remote connection. I was advised to provide a web service to serve as a gateway between my application and the database.
An alternative solution I can think of is, to look for a mysql server that allows remote connection. I find it difficult to look for tutorials where I can clearly understand web services in java. I've done some research and I was told I could use PHP to write a web service and generate JSON file, then I could parse it in java. But If I do that, all my JDBC codes have to be recoded/removed.
Is it possible to connect to the database remotely without having my JDBC codes removed? Or can I incorporate Tomcat with JDBC? Thank you!
Here's what I get..
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Caused by: java.net.ConnectException: Connection timed out: connect
Your questions seems to be leading to an architecture similar to this:
But unlike what your question suggests - the Server Side Module doesn't relay DB queries from the desk-top application to the database - it acts as a server to your desktop application which becomes a client application.
This means re-architecturing (not a real word I think) of your application - but a common best practice. The server side module is responsible for authenticating and authorizing your users to ensure that no one can perform malicious activities on the database.
There is no short answer here - you need to consider if this is the direction you want to go with.
An alternative as others suggested is to allow direct access from the desktop application to the database via a firewall. I assume you are posting here since the people responsible for the database's integrity told you you shouldn't do that.
I think you don't need web service here. To address your issue, you can enable remote access in your MySQL server. Please follow the instruction which is available in this blog. If your MySQL server hosted in Windows environment please refer this document also.
After that update your JDBC URL with remote MySQL server domain or IP address.
To connect Database with web services is higly not recomandable.
Think this way web services is having input/output pattern.
so you want fetch data from table1, with method1.
table2 with method2 etc...
so provide remote access for that database server this could be fine.
You can allow remote connections in MySQL. You're going to have to search for a guide for the specifics depending on the server it's running on (here's one for debian). Although if you don't trust the people running the application or the DB contains sensitive data I would strongly advise you not to do that and use the PHP instead as it introduces a lot of security issues. If it's only IP address that needs to connect at any one time you should only allow that IP address to connect, that will make the security vulnerabilities smaller.
There is nothing stopping you from accessing a remote database using JDBC apart from firewall rules. It is generally considered a bad practice to expose your db credentials over to client side - even if hardcoded in code. This is architecturally flawed approach and should not consider for more than school homework.
However, if you need the solution, you will have following options to look at:
1) Check for the ip address on which Mysql runs. It must not be localhost but a IP like 192.168.1.2, etc..
2) Check if the JDBC error is Authentication related, then you will need to add right permission to the user account. MySQL security model ties the username and the IP from where the user can login. You may need to correct those.
If both are correct, please post the exact exception which you are getting while using JDBC.
You don't have to use a web service. You can implement any form of client/server communication e.g. web services, REST, RMI, native sockets etc. It would be worthwhile to investigate these and determine which is most appropriate. However....
This strikes me as an architectural issue rather than an issue surrounding specific technologies. It sounds to me like you're being guided down the path of implementing some service that allows you not only to access the database, but provide a richer API. e.g. you don't want your client to insert into a table. You should provide an API to add to a shopping basket. i.e. you're working at a different level of abstraction (in the future you may implement your database in a completely different fashion and you don't want to change your clients).
The above is a standard pattern in the Java EE world and wider.
I need to open, read and insert items into an online SQLite database from an Android app. I know url, username and password. In JavaSE i would do the following:
Class.forName("com.mysql.jdbc.Driver");
Connection dbConnection = DriverManager.getConnection(URL, USER, PASSWORD);
I read that I can't do this in Android because there is not a JDBC Driver (there is a "SQLite.JDBCDriver" but it is not documented and not recommended).
So which is the easiest way? I asked to Google but it looks like he either doesn't know.
You should expose your datasource like this via an intermediary such as a Web Service for at least the following reasons:
someone has direct access to your datasource and can read, manipulate or destroy the data
abstraction; you can control the way in which the data is sent and how it's represented. Should the database tables/objects change, you'd only have to change the web service instead of force an update (in some cases)
JSON interaction is very well supported on Android out of the box, whereas JDBC isn't (for previously documented reasons)
I'm sure there are plenty of more reasons, but the above are the most prevalent in my mind.
There is no official support for JDBC on Android. There is a private SqlLite driver, but it's not recommended as it is unsupported and might go away in the future.
Read these:
Does Android Support JDBC
http://groups.google.com/group/android-developers/browse_thread/thread/cf3dea94d2f6243c
http://code.google.com/p/sqldroid/
So the recommended way is to not use internal (private) SQlite driver and instead create a REST layer on server through which you access data. This is a recommended way as it minimizes load on device side and also gives you opportunity to create authentication on the server side - having publicly accessible JDBC connection is a big no-no.
I am making an Android application. Since it is so simple, I first thought I could simply eliminate the need for Java application on the server which acts as a middleware. I tried directly connecting to the database using the JDBC driver for MySQL but my program is crashing so I'm not sure if Android "supports" the JDBC driver for MySQL.
So I am thinking of how to implement the application. Basically the application writes some data from a remote MySQL database and retrieves some data from a remote MySQL database.
Do I connect to a Java server program using sockets (or some other method of communication)? Or could I implement a direct connection to the MySQL database from the client application?
I tried directly connecting to the
database using the JDBC driver for
MySQL but my program is crashing so
I'm not sure if Android "supports" the
JDBC driver for MySQL.
Never never never use a database driver across an Internet connection, for any database, for any platform, for any client, anywhere. That goes double for mobile. Database drivers are designed for LAN operations and are not designed for flaky/intermittent connections or high latency.
Do I connect to a Java server program
using sockets (or some other method of
communication)?
It doesn't have to be Java. It just has to be something designed for use over the Internet. As Mr. King's comment suggests, Web services have been used for this for much of the past decade. For Android, REST Web services are probably the easiest to consume, since there is no built-in support for SOAP or XML-RPC. But whether the Web service is implemented in Java, or PHP, or Perl, or SNOBOL, is up to you.
Well, OK, perhaps SNOBOL won't be a viable option. :-)
I know this might be a little late but as I ran into the same problem with a project at school I wanted to share my solution with you as you might profit out of my experiences.
Android is bad for Database-Operations so creating a normal Database-Controller wasn't a thing. Instead I created a Server in Java which handles all Database-related stuff and can also be extended (in my case I used a Feedback-function, too).
The Github-REPO is: https://github.com/Cedced-Bro/Public-Server You can check it out and this is open-source so you can use and contribute to it if you have more ideas to it.
To answer your question more properly: I would strongly suggest to NOT grant all users direct access to your DB as you can run into security issues with malicious users. This was the reason why I created this controller in the first place instead of just a PHP "forwarding"-server.