Javatpoint Logo
Javatpoint Logo

Java URL openConnection() Method

The openConnection() method of URL class opens the connection to specified URL and URLConnection instance that represents a connection to the remote object referred by the URL.

It should be noted that a URLConnection instance does not establish the actual network connection on the creation. This will happen only when calling URLConnection.connect().


The openConnection method is overloaded as given in the following table.

No. Method Description
1. URLConnection openConnection() Returns a URLConnection instance that represents a connection to the remote object referred to by the URL.
2. openConnection(Proxy proxy) throws IOException Same as openConnection(), except that the connection will be made through the specified proxy; Protocol handlers that do not support proxying will ignore the proxy parameter and make a normal connection.


The URLConnection linking to the URL.


IOException - if an I/O exception occurs.

Example 1

Test it Now


The mime type is : text/html; charset=iso-8859-1
 The time out time of connection is : 0

Example 2

Test it Now


<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>JDBC Tutorial | What is Java Database Connectivity(JDBC) - javatpoint</title><link rel="SHORTCUT ICON" href="/images/logo/icon.png" />
<link rel="stylesheet" type="text/css" href="/link.css"/>
<meta name="keywords" content="java, jdbc, tutorial, api, drivers, odbc"/><meta name="description" content="Java JDBC Tutorial or What is Java Database Connectivity(JDBC) with examples on Driver, DriverManager, Connection, Statement, ResultSet, PreparedStatement, CallableStatement, ResultSetMetaData, DatabaseMetaData, RowSet, Store Image, Fetch Image, Store file, Fetch file etc."/><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><link rel="canonical" href="" />
Next TopicJava URL Class

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA