How can I find out the URL and port for an Oracle database?
Example:
"jdbc:oracle:thin:#host:port:dbName","userName", "password");
Is there an SQL command or log/configuration file I can look at?
With oracle, there is a tnsnames.ora file which defines database addresses. This file is normally found in $ORACLE_HOME/network/admin and is used by oracle clients like sqlplus or Toad. Here is a sample tns entry:
ORA11 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ORA11)
)
)
From this entry you can work out that your jdbc connection string would be:
jdbc:oracle:thin:#hostname:1521:ORA11
By reading the documentation which came along with the JDBC driver in question.
In case of the Oracle JDBC thin driver, you can find it here.
Specifying a Database URL, User Name, and Password
The following signature takes the URL, user name, and password as separate parameters:
getConnection(String URL, String user, String password);
Where the URL is of the form:
jdbc:oracle:<drivertype>:#<database>
The following example connects user scott with password tiger to a database with INSTANCE_NAME orcl through port 1521 of host myhost, using the Thin driver.
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:#myhost:1521:orcl", "scott", "tiger");
If you want to use the default connection for an OCI driver, specify either:
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci:scott/tiger#");
or:
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci:#", "scott", "tiger");
For all JDBC drivers, you can also specify the database with a Oracle Net keyword-value pair. The Oracle Net keyword-value pair substitutes for the TNSNAMES entry. The following example uses the same parameters as the preceding example, but in the keyword-value format:
Connection conn = DriverManager.getConnection
(jdbc:oracle:oci:#MyHostString","scott","tiger");
or:
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci:#(description=(address=(host= myhost)
(protocol=tcp)(port=1521))(connect_data=(INSTANCE_NAME=orcl)))",
"scott", "tiger");
Related
This is the code that I use to connect with the Oracle database that is on my pc:
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection co = DriverManager.getConnection("jdbc:oracle:thin:#localhost:1521:etecsa", "system", "asd");
It works but if I change localhost for an ip it can not connect to the database. I already deactivated the firewall but nothing.
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection co = DriverManager.getConnection("jdbc:oracle:thin:10.8.6.50:1521:etecsa", "system", "asd");
Where can I configure the oracle database to accept the connection from a specific ip and not only from localhost?
Check the documentation for DB URL
jdbc:oracle:driver_type:[username/password]#database_specifier
so in your case (if etecsa is SID) the url will be #host:port:SID
jdbc:oracle:thin:#10.8.6.50:1521:etecsa
if etecsa is a service name then use #//host:port/service_name
jdbc:oracle:thin:#//10.8.6.50:1521/etecsa
In my java application, I need to connect to a teradata database.
String DB_URL = "jdbc:teradata://***.***.***.***,tmode=ANSI,charset=UTF8";
String USERNAME = "***";
String PASSWORD = "***";
con = DriverManager.getConnection(DB_URL, USERNAME, PASSWORD);
When I try to connect I get a java.net.UnknownHostException.
Do I need to specify a hostname to connect to a teradata sql server? At the moment, I am only using the ip address.
The connection URL should end the hostname part with / as far as I'm aware
jdbc:teradata://***.***.***.***/tmode=ANSI,charset=UTF8
I am completely new to java, and I want to make a connection to a remote SQL server 2008 R2 database (like 192.168.17.11) and load data from it.
Please suggest alternative ways if you know any.
First you must have JDBC driver for MS SQL, you have two jars (jtds-1.2.5.jar or sqljdbc4-2.0.jar), which added to your classpath
Second you need to create your connection as below:
String password="pass";
String driver= "net.sourceforge.jtds.jdbc.Driver"; // For sqljdbc4, use: com.microsoft.sqlserver.jdbc.SQLServerDriver
String username="user";
String URL="jdbc:jtds:sqlserver://serverIP:port/dbname"; // For sqljdbc4, use: jdbc:sqlserver://serverIP:port;databaseName=dbname
Class.forName(driver);
Connection conn = DriverManager.getConnection(URL, username, password);
// Use your connection here
// Don't forget to close the connection
Currently none of my hostnames are resolving to my server which uses no-ip DDNS related to this issue. Is it possible to use the server IP address instead of the DDNS domain name in the JDBC connector?
private static final String driver = "com.mysql.jdbc.Driver", host = "jdbc://mysql:no-ip.hostname/", dbName = "databaseName", username = "username", password = "password";
Connection conn = (Connection) DriverManager.getConnection(host + dbName, username, password);
Yes, that should work. I've never used a JDBC driver that would not accept an IP address for the host.
In my program I am trying to connect to a mySQL database. This program is written in Java.
I am trying to connect to my database with this code here (? is a place holder b/c I dont know what does there.)
Connection conn = DriverManager.getConnection("jdbc:sqlite:*?*");
I need someone to help me replace the ? to connect to my database. I know the IP (Just call it ***.***.*** for security reasons, the port which is 3306 and the database is called devicede_Test).
Please help me replace the ? with the correct string with the info above, thanks!
Try this
Connection conn = DriverManager.getConnection("jdbc:mysql://***.***.***:3306/dbname");
Try this:
String url = "jdbc:mysql://localhost:3306/mysql";
Connection con = DriverManager.getConnection(url,"root", "");
SQLIte is not the right driver here. Use:
Connection conn = DriverManager.getConnection("jdbc:mysql://**.***.***.***/devicede_Test", user, pass);
The JDBC URL format for MySQL Connector/J is as follows, with items in square brackets ([, ]) being optional:
jdbc:mysql://[host][,failoverhost...][:port]/[database] ยป
[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...
Here is a sample connection URL:
jdbc:mysql://localhost:3306/sakila?profileSQL=true
Source : http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html