---
title: "jdbc网络断开-检测网络连接状态"
author: "ayanline"
date: "2011-08-30T01:33:25Z"
tags: []
categories: ["开源软件"]
slug: "jdbc"
draft: false
lastmod: "2011-08-30T01:33:25Z"
id: 1160992
url: "https://ayanline.iteye.com/blog/1160992"
---

```java

public static void main(String[] args) {   
        URL url = null;   
        try {   
            url = new URL("http://baidu.com");   
            try {   
                InputStream in = url.openStream();   
                in.close();   
                System.out.println("网络连接正常！");   
            } catch (IOException e) {   
                System.out.println("网络连接失败！");   
            }   
        } catch (MalformedURLException e) {   
            e.printStackTrace();   
        }   
    }  

```