1

I have created a Java Eclipse app with database tables from Oracle 11g. It works fine but only in my local pc. How can I make these tables work into another pc? Maybe I have to put them in the application folder? The app is connected with the db via JDBC Connector.

The connection logic is as follows:

try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch (ClassNotFoundException e) {
    System.out.println("Unable to load the driver class!");
}
String url = "jdbc:oracle:thin:@localhost:1521:xe";
String user = "system";
String password = "xxxxpw";
Connection connection = null;
try {
    connection = DriverManager.getConnection(url, user, password);
    System.out.println("Connection succeed!!");
}
catch (SQLException e) {
    System.out.println("Couldn't take connection!");
} 
Richard Chambers
  • 16,643
  • 4
  • 81
  • 106
Grigoris Loukidis
  • 383
  • 2
  • 7
  • 23
  • 1
    Where does the Oracle database server run? An what do you mean by "putting tables in the application folder"? These tables reside in the database, not in some folder (unless of course they're actually not database tables but eg a dump file, csv file created from a table or whatever? – fvu Jun 04 '15 at 11:40
  • the oracle database runs in my local pc..yes , these tables reside in the db , not in any other folder. – Grigoris Loukidis Jun 04 '15 at 11:42
  • 1
    Just guessing, but did you configure the JDBC connection to use 127.0.0.1 or localhost as the db address? If so, replace that by your machine's external address. – fvu Jun 04 '15 at 11:44

2 Answers2

1

You really have two options with Oracle 11g and an alternative to Oracle 11g.

The first is to use your PC or some other PC as a database host and have any other instance of your application reference your databases on that database host. This may require a change in the JDBC connection to specify where the host is and there are some other issues that may need to be addressed depending on your environment. See below for a brief discussion.

The second is to replicate the database on each PC that will be running your application. This will require installation Oracle 11g on each PC and then replicating the database on your PC to the other PC. See What is the easiest way to transfer Oracle database from one PC to another?

A third option is to change the database engine to something such as SQLite which uses one or more files allowing for easy replication. Take a look at some of the answers for Java and SQLite.

Concerning the first option with Oracle 11g of sharing a database, there are some runtime environmental issues you will need to consider.

You will need some way of being able to specify the JDBC connection to the PC or server running the database. This gets into directory lookup for PCs and whether your environment has fixed IP addresses or not as well as how mobile are the devices using your application. Firewalls can block connections as well.

After looking at your connect string logic, if you are going to host the database on a particular PC you will need the hostname of the PC or you will need the IP address of the PC (see Java JDBC - How to connect to Oracle using Service Name instead of SID which provides some examples of connect strings and their formats).

In your connect string the server name of localhost is the PC on which your application is running. So if you move your application with that connect string then running the application on the PC to which it was moved will have the application looking on that PC for the Oracle 11g database engine and the database.

So you need to change localhost to either the host name of your PC with the Oracle 11g database or you will need to change localhost to the IP address of the PC running the database.

It also looks like you need to add // to the beginning of the host name.

Community
  • 1
  • 1
Richard Chambers
  • 16,643
  • 4
  • 81
  • 106
  • do you know how can i set as jdbc using ip , my pc's ip? – Grigoris Loukidis Jun 04 '15 at 12:25
  • @grlouk, please update your question with the source lines used to open your database connection showing the `getConnection()` logic so that we can see what you are doing. – Richard Chambers Jun 04 '15 at 12:30
  • try { Class.forName("oracle.jdbc.driver.OracleDriver"); } catch (ClassNotFoundException e) { System.out.println("Unable to load the driver class!"); } String url = "jdbc:oracle:thin:@localhost:1521:xe"; String user = "system"; String password = "vertigo1321993"; Connection connection = null; try { connection = DriverManager.getConnection(url, user, password); System.out.println("Connection succeed!!"); } catch (SQLException e) { System.out.println("Couldn't take connection!"); } – Grigoris Loukidis Jun 04 '15 at 12:35
0

Export DB schema and seed your data into another PC and you are good to go.

Muhammad Suleman
  • 2,892
  • 2
  • 25
  • 33