What is the actual difference between the following 2 declarations of JDBC URL?
1. jdbc:oracle:thin:#//hostname:1521/servicename
2. jdbc:oracle:thin:#hostname:1521:sidid
Reason for the question:
URL1 works for only for some specific oracle database whereas URL2 seems to work for all types of data. Can the URL2 format be used for the servicename also?
Issue:
I got the following error when I used URL1 against certain database.
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
The Connection descriptor used by the client was:
//hostname:1521/sidid
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:280)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:328)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:361)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:151)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:595)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
Solution:
Used URL2 and it fixed the above TNS error.
Edited:
Changed the format of the URL to servicename from sid.
Why it is throwing an error when just the format its expecting for a sid is different from service?
Related
I know that it's used at the beginning of a URL string to create a connection to MySQL (or similar DB system), but, what is this portion of the connection string referred to as and what exactly is its function/role?
MySQL example:
String url = "jdbc:mysql://localhost:3306/?useSSL=false";
H2 example:
String DB_URL = "jdbc:h2:~/DB_NAME";
The generic format of the connection URL is:
protocol//[hosts][/database][?properties]
for your question:
String url = "jdbc:mysql://localhost:3306/?useSSL=false";
jdbc:mysql: is protocol part.
hosts part is written in the format of host:port which is- localhost:3306
useSSL=false is properties in key-value pair to disable SSL.
The connection string should be:
String url = "jdbc:mysql://localhost:3306/{dbName}?useSSL=false";
You can use this reference for more explanation-
Connection URL Syntax:
From The components of a URL
A scheme. The scheme identifies the protocol to be used to access the resource on the Internet. It can be HTTP (without SSL) or HTTPS (with SSL).
In this case, it is jdbc followed by a more specific driver implementation (which is usually registered via the DriverManager).
The jdbc:{database name} is protocol part. database name can be mysql, derby, oracle. The next part of the connection string depends on the individual DriverManager implementation. See below connection string :
MySQL : jdbc:mysql://localhost:3306/mysql
Oracle : jdbc:oracle:thin:#localhost:1521:xe","system","oracle"
Derby : jdbc:derby://localhost:1527/myDB;create=true;user=me;password=mine
It is referred as JDBC connection string (URL) or Database URL.
To access a database from a Java application, you must first provide the code to register your installed driver with your program. Once you have registered the driver, you can open a connection to the database with the static getConnection() method of the java.sql.DriverManager class. The type of the object returned is java.sql.Connection.
Specifying a Database URL and Properties Object to get connection
The following signature takes a URL, together with a properties object that specifies user name and password (perhaps among other things):
getConnection(String URL, Properties info);
Where the URL is of the form:
`jdbc:oracle:<drivertype>:#<database>`
Reference
I'm trying to connect to a URL in an AsynTask but am having trouble.
Document doc = Jsoup.connect("https://www.gasbuddy.com/home?search=33444&fuel=1").get();
gives me an error in my log saying:
Error Connecting: failed to connect to www.gasbuddy.com/104.17.148.191 (port 443) after 30000ms
After doing some research, I believe I need to connect to the baseURL. However, I'm not sure how to do this. I've tried:
URL absoluteUrl = new URL(new URL("https://www.gasbuddy.com/home?search=33444&fuel=1"), "script.js");
Document doc = Jsoup.connect(String.valueOf(absoluteUrl)).get();
But I get the same error in my my logs.
Edit: I get the same error on any website I try connecting too ("https://www.yahoo.com/", "https://www.google.com/", etc) I'm on a a public Starbucks Wifi at the moment, not sure if that matters.
I write a java code to access(connect) intuit quickbooks using this keys
String consumerKey = "qyprdTCZTGRhIYkRPU5OeXjd7rJiMS";
String consumerSecret = "L1ek9k7zX55rVXPlj5FikHYJgCnxfWCKBtjt81Ti";
String accessToken="qyprd6GGQ9w3OfmN0tg1M5xLzWdWF9RZOaMRVkb43tXNO6kG";
String accessTokenSecret = "RMKyYmrrqQY0xem2Cxj3pQeiOJwSR3ceT90wESWH";
String companyId = "1386063640";
String appId="b7qs4z3s2p";
when i execute this i got these errors
connection refused
or
java.net.UnknownHostException: sandboxquickbooks.api.intuit.com
please any one help to getting out this isue.
Simply put, the computer does not recognize the server you re attempting to connect to. The address sandboxquickbooks.api.intuit.com is not able to be located by your computer when executing the code. Take a look at this post for a little more detail...
java.net.UnknownHostException: Invalid hostname for server: local
My guess is it is spelled wrong, or they changed the address/url.
Correct sandbox base url is - https://sandbox-quickbooks.api.intuit.com
Refer java sample app here-
https://github.com/IntuitDeveloperRelations/QuickbooksV3API-Java
Document doc1;
String url="http://www.google.com";
url= url +" and 1=1";
doc1=Jsoup.connect(url).get();
Here there is no problem with the connection as the following code gives no exception. The exception is generated only when I try to get the HTML code with the above code.
Document doc1;
String url="http://www.google.com";
url= url +" and 1=1";
Jsoup.connect(url);
Thanks!
JSoup.connect doesn't actually try to connect to the website. If you look through the documentation, you'll see that it only creates a Connection object. You can chain method calls on the Connection to set cookies, user agent, and other stuff before calling get, execute, post, or one of the other methods that will actually send the request.
(Here's another documentation link that might be easier to browse. Unfortunately, Javadoc's use of frames makes linking awkward.)
According to Jsoup javadoc:
Jsoup.connect(String url):
Creates a new Connection to a URL. Use to fetch and parse a HTML page.
Connection.get():
Execute the request as a GET, and parse the result.
So in the first sample you are querying google and getting an IOException because of the invalid URL but not in the second sample (no query is made)
Jsoup.connect doesn't actually connect to anything. It just creates a Connection object. If you want to set any special properties of the connection, you can do it before you call get() which is what actually connects.
As for why you get an exception: probably because http://www.google.com and 1=1 is not a valid URL.
I need to make a URL request from Java.
The problem is the following :
in Java, while creating the URL I can not skip the protocol (http:// or https://) ... and in the browser I only get to access the resource if I put as address the IP (without http:// or https://).
Any ideas?