简体   繁体   中英

how to connect client computer to use Sqlite database which is installed in the server computer using java programming?

I am developing a commercial desktop application using java Programming Language and i am using Sqlite as my database of choice. But in a situation whereby i want this software to be install to two or more client computer and my wish is that the client computer installed software should make use of server computer software Sqlite database(one common database). My Questions are: What are the proper procedures to achieve this using Networking and java? and What is the proper connection strings to apply to the client and server computers ?

Below is my server connection that works for me:

import java.sql.*;
import javax.swing.JOptionPane;

public class dbconnection {
    Connection conn = null;

    public static Connection ConnectDB() {
        Statement stmt = null;
        try
        {

            Class.forName("org.sqlite.JDBC");
            Connection conn = DriverManager.getConnection("jdbc:sqlite:myDatabase.sqlite");
            System.out.println("Connected database successfully...");
            return conn; 
        }
        catch(Exception e)
        {
            System.out.println("Exception 1: "+ e);
            return null;
        }

    }
}

Thanks so much!!, As you provide solution for me.

From when to use SQLite :

SQLite strives to provide local data storage for individual applications and devices.

If you want to implement some kind of client/server architecture using SQLite you can achive it like (source: serverside database )

Server-side database
Systems designers report success using SQLite as a data store on server applications running in the datacenter, or in other words, using SQLite as the underlying storage engine for an application-specific database server.
With this pattern, the overall system is still client/server: clients send requests to the server and get back replies over the network. But instead of sending generic SQL and getting back raw table content, the client requests and server responses are high-level and application-specific. The server translates requests into multiple SQL queries, gathers the results, does post-processing, filtering, and analysis, then constructs a high-level reply containing only the essential information.
Developers report that SQLite is often faster than a client/server SQL database engine in this scenario. Database requests are serialized by the server, so concurrency is not an issue. Concurrency is also improved by "database sharding": using separate database files for different subdomains. For example, the server might have a separate SQLite database for each user, so that the server can handle hundreds or thousands of simultaneous connections, but each SQLite database is only used by one connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM