remote access sqlite or mysql database - java

I am using sqlite for my offline J2EE applicaion . But I have two client and I want to connect database of two clients together .
Can I do it with sqlite or I have to change mysql ? And can you show me which host can help me solve this problem.

You cannot access SQLite remotely just using its native capabilities without some kind of an extra bridge, e.g ssh tunnel or a custom proxy daemon. MySQL and a number of other databases do provide remote access. There are a lot of hosting providers that manage MySQL for you, e.g Rackspace, Amazon, Bluehost, and many others, or if you just get a host with Linux and root access you can install it yourself, and there are many providers that can give you that - I personally like Linode.

Related

How would my MariaDB database be accessed by other people using JDBC?

For a university project, we were taught to use JDBC to connect to a MariaDB database. The database was created on localhost:3306.
This is what we used:
Connection connection = DriverManager.getConnection("jdbc:mariadb://localhost:3306/dbname", username, password);
I am now doing an online group project using GitHub. How would my group partners gain access to this database if it is not on their local machine? I read somewhere about SQLdump but I couldn't seem to get it working. If I successfully did an SQLdump, could I just include the file in github and it would work for them?
Otherwise, would I need to put it on a public server?
First you need to decide whether you want to share the data or the database:
share data
This will put copies of data to your group members. Every one of you has his/her own copy in a locally installed MariaDB database, and every one of you can access it using localhost in the connection string.
https://mariadb.com/kb/en/backup-and-restore-overview/
The sql dump file can be easily shared with others. If you find the backup/restore stuff is getting tedious and merging the data is a requirement, check for https://www.liquibase.org/, or even consider going for the shared database.
shared database
Ensure your MariaDB server not only binds to localhost (127.0.0.1) but also to your machine's public IP.
open your machine's firewall to allow access to this IP. Maybe you have to look at more firewalls to be opened (e.g. your router).
create user accounts that are allowed to connect from their respective host or from any host (https://mariadb.com/kb/en/create-user/#account-names)
You can do all that from your local development machine. If you find the network or uptime requirements are not comfortable, switch to a dedicated server. This may be a cloud solution or on-premise, whatever is comfortable for you.

Creating Database in MySQL in Java netbeans in different machines

I have created a standalone application as a school project. The major problem we are encountering is that since it has Java as front-end and MySQL as back-end (compulsory), and we have created a database that solely belongs to one computer, we cannot run the same project on different machines because it won't have the required database, the tables, or the same username and password we used to connect to MySQL.
So my question is **How can I connect to MySQL server in different Machines? **
For database and Tables, I could run a sql file, but that will happen when I would be connected to the MySQL server. Also I am developing the project at my home computer, and I want to run the project on different computers who are connected to my computer by no means .
You a following options
Shared drive : Attach database stored on remote shared drive to a local SQL Server read here
Connect to remote SQL Server instance from local computer - better if they are in same LAN - Steps here
If you want to package DB with app where you have predefined data and you dont want to save transactional data - use inMemory DB. They will load when you application starts up.
Already your application can work using different machine.
You have only to change the localhost string in your connection string with the IP of the MySQL machine :
DriverManager.getConnection("jdbc:mysql://localhost/database?"+ "user=sqluser&password=sqluserpw");
And make sure that remote access are enabled in your MySQL configuration. You can find more about it here.
Instead of using localhost in your database connection string, you should use the ip or aname of the database host
e.g.
jdbc:mysql://IP:3306/db?user=user&password=password
jdbc:mysql://A-NAME/db?user=user&password=password
Just make sure that port 3306 is open and that you have access on the system the databasse is hosted on

Retrieve data from online database in java

I have always used a database located in my pc, so the steps to connect to it are:
connect to my local db using jdbc
perform queries
show results
now, i want to know what are the steps if the database is located in an online server?
some guides,tutorials are very appreciated.
Since you will be connecting to a remote database I would advise you to read about secure connections using JDBC. See this question, for example. You don't want to interact with a remote database without something like SSL to protect the confidentiality of the data.
Once you think you have secured your connection, you can use a tool like Wireshark to make sure that the packets that are going to and coming from your database are in fact opaque.
Furthermore, as others have said, not much changes if you already have a working connection to a local database, it's a matter of changing your URL from jdbc:mysql://localhost:port/database to jdbc:mysql://ipaddress:port/database.
From my experience, I found that some hosting companies block database access from unknown IP addresses, so it's possible that you'll have to go to your CPanel and whitelist your IP address.
Once your database connection is setup, the code you use to query the database should look the same.
Some useful links:
JDBC Best practices
JDBC Tutorials from Oracle
You have to change database url only to be like
jdbc:mysql://IP:3306/databasename
also username and password.
some hosting company like godaddy create database in localhost(in the same host) which doesn't need to change anything in your code.

Connecting Access Databases remotely?

Currently I have a Java application which performs all I wanted and the limitation
in it is "It only resides on the Local machine for which it needs to work". I have the Access Databases located on a Remote Server and I install the Java app on the remote server to connect the databases using a connection string jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=D:\\DATA\\DPPI\\DATA\\DPPI\\DPPIPR01.mdb;
It connects to Access Databases and do all the business logic with them.
Enhancements (to be done):
Making the application online - not a big issue.
Connecting the databases remotely - its the only concern.
If I make the Application Online the Access Databases need to be connecting through network (somewhat like IP or some web address).
Problem:
But after going through this Connect to Access database remotely It seems my requirement can not be completed.
Is there any way if I'm able to upload the database to the online web hosting server and access the database from there only? If yes, then how should I do the connectivity since Access Database connects by giving the fully qualified name containing drive letter and all.
But how should I proceed further so that I may be able to connect the mdb Databases remotely?
ADO Solution:
But after going through the link: http://webcheatsheet.com/ASP/access_connection_strings.php, it seems we can perform remote Access Database connectivity.
The solution for the ADO is something like:
connectionString="Provider=MS Remote; Remote Server=http://your_remote_server_ip;" &_
"Remote Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\your_database_name.mdb"
I'm a tad confused to how Access Database we can connect.
There is one more question in my head.
I'm making use of Type-1 Driver. Should the Type-4 Driver support the remote connectivity?
If your application is a server side application (like a web application) and your server's OS is Windows then theoretically it is possible to use your Access database. In this scenario, the Access database is local to your application. In your connection string you can simply use the path to the Access database inside your server's file system.
But keep in mind, that Access is a desktop database not made to use it as a server database. This can lead to poor performance and maybe system crashes. And it is possible that there are some licencing issues for this use case.
So even it may be possible to use Access with a server application it is strongly recommended to use a real server database like MySQL, MS SQL Server, etc. Even an embedded database like Apache Derby or H2 would be a better fit.
If your application runs at client side like a fat client, then your only chance to use Access is to put it on a network filesystem, so it is visible from every client. But this works only inside a LAN. If you cannot put it on a network filesystem then you have to use a real server database.
Do not use Provider=MS Remote (RDS) for new development. Here is a quote from the MSDN article
Microsoft OLE DB Remoting Provider (ADO Service Provider)
Important
Beginning with Windows 8 and Windows Server 2012, RDS server components are no longer included in the Windows operating system (see Windows 8 and Windows Server 2012 Compatibility Cookbook for more detail). RDS client components will be removed in a future version of Windows. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Applications that use RDS should migrate to WCF Data Service.
As others have suggested, you should seriously consider using a different back-end database for this particular application.
What if I'm able to call another java application residing on the Server housing the Microsoft Access Databases? Can you please let me know if it can be the solution such that I will have the division of my application into two:
1. The Online java Application performing 2 things: Accepting the requests coming in and waiting for the response to come from another application running on the Server housing the Microsoft Access Databases.
2. The Java application installed on the Server housing the Microsoft Access Databases only responsible for connecting and returning the DTO (Data Transfer Objects) -or some kind of objects in Collections.
So, I would expect a serverside program to handle the communication with the DB and the client application would communicate with the server app.
Please let me know if I should proceed in this manner.
it can be done by marking the traffic and queueing the traffic from the server---to----remote site ---(QOS..quality of service ) .....the two sites will be connected through VPN methods to reduce the unnecessary hops that will improve the latency plus add the security , thus server and remote site will logically act as if they are on the same network (LAN)
regards ,
Ali Rehan

How to access db in vps

Hi in order to access the db on my vps i have to previosly connect via ssh I have tested this with MySQL WORKBENCH and it works.
But Netbeans (working ide) does no provide ssh connection when creating a db connection so I cannot connect my local application to my new server.
How can I go around this?
How can i set my jta datasource to deal with this?
Thank you very much
Best Regards
Ignacio
There are two ways to archive connectivity from netbeans:
REALLY UNSAFE Method: Make MySql listen on the network-interface connected to the internet. Set bind-address in your mysql-configuration file to 0.0.0.0 and mysql will listen on all interfaces. http://dev.mysql.com/doc/refman/5.6/en/server-options.html#option_mysqld_bind-address You can then access MySql from everywhere on the internet. Remember: This is a serious security vulnerability! Search Google and you will find a lot of articles explaining in great detail why.
Safe method: SSH can do port-forwarding. It means, that one port on your local machine listens for connections and tunnels all traffic well encrypted to the remote port. On linux this is done with ssh -L 3306:localhost:3306 YOUR_SERVERS_IP. You can then access your MySql-Server on localhost:3306 like it is running on your local computer (just slower). On Windows Putty can be configured to do the same thing. I don't remember exactly where, but in the dialog where you setup your connection (before the command-prompt) you also can configure port-forwarding.
Write an application to run on your server, which takes care of Authorization and exposes and API to users (like the Youtube-api for example, which has some public methods but also some requiring authentication). This could be done in numerous different ways like XMLRPC (using a webserver and some web-application) or a custom protocol. This is probably the one most suitable for production use.
Poke some holes in your firewall to let NetBeans connect?
I would recommend you simply copy the database to your development environment and don't touch the VPS unless you're ready to 'release'.

Categories

Resources