How to connect to a remote database?
There are two things that I am having trouble understanding:
1. How to connect to the server. I do not know if I should use localhost or not? (I am linking to a database that is not on my local machine, if that matters)
2. How to connect to the correct database, as there are a couple of databases under that server
This is what I have so far:
MAIN -> My Server
1433: TCP/IP Port
DB_Accounts -> The Database I want to connect to
String dbURL = "jdbc:sqlserver://MAIN\\SQLEXPRESS:1433/DB_Accounts;user=myuser;password=mypass;"; // Connect the server and the database
thanks for any help given
Re: How to connect to a remote database?
Quote:
Originally Posted by
ace84
There are two things that I am having trouble understanding:
1. How to connect to the server. I do not know if I should use localhost or not? (I am linking to a database that is not on my local machine, if that matters)
2. How to connect to the correct database, as there are a couple of databases under that server
This is what I have so far:
MAIN -> My Server
1433: TCP/IP Port
DB_Accounts -> The Database I want to connect to
String dbURL = "jdbc:sqlserver://MAIN\\SQLEXPRESS:1433/DB_Accounts;user=myuser;password=mypass;"; // Connect the server and the database
thanks for any help given
Hi,
As you mentioned, if the DB exists in the remote server, You need to get the Correct IP where the correct DB exists and then U need to connect like the code below.
Code Java:
Connection con = null;
try {
String URL = "jdbc:oracle:thin:@121.340.19.249:1521";
String dataBaseName = "DBName";
String userName = "username";
String password = "password";
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
URL+":"+dataBaseName, userName,
password);
} catch (Exception e) {
e.printStackTrace();
}
return con;
Try this.
Regards,
Janarthanan.K
Re: How to connect to a remote database?
Hey thanks for your help,
I tried the code that you gave and I it didn't work because I am trying to connect to sql server database rather than a oracle db.
Re: How to connect to a remote database?
Quote:
oracle.jdbc.driver.OracleDriver
you had tried after modifying driver for sql server and url name.
Click Here
Microsoft help
Re: How to connect to a remote database?
Quote:
Originally Posted by
ace84
Hey thanks for your help,
I tried the code that you gave and I it didn't work because I am trying to connect to sql server database rather than a oracle db.
The code posted by janarthanan seem to be fine. If you are using MySQL then change the Class.forName to the correct driver. Your IDE can point to the correct driver (Netbeans/Myeclipse etc.)