liangoogle

          liangoogle
          隨筆 - 9, 文章 - 0, 評論 - 3, 引用 - 0
          數據加載中……

          jsp使用servlet在xml處添加的信息q.html為這個servlet類的鏈接地址

          <servlet>
          <servlet-name>sda</servlet-name>
          <servlet-class>com.servlet.Test</servlet-class>
          </servlet>
          <servlet-mapping>
          <servlet-name>sda</servlet-name>
          <url-pattern>/q.html</url-pattern>
          </servlet-mapping>

          posted @ 2011-04-26 01:25 haojinlian 閱讀(136) | 評論 (0)編輯 收藏

          java代碼實現連接mysql數據庫

          注意修改下面數據庫的名稱、登陸的賬號密碼。
          我用的數據庫名是:test
          賬號密碼都是:root
          =================================
          import java.sql.*;
          public class JDBCTest {
          public static void main(String[] args) {
          // 1. 注冊驅動
          try {
          Class.forName("com.mysql.jdbc.Driver");
          } catch(ClassNotFoundException ex) {
          ex.printStackTrace();
          }
          // 聲明變量,使用,而后關閉
          Connection conn = null;        //數據庫連接
          Statement stmt = null;         //數據庫表達式
          ResultSet rs = null;             //結果集
          try {
          //2. 獲取數據庫的連接
          conn = DriverManager.getConnection
          ("jdbc:mysql://localhost:3306/test","root","root");
          //3. 獲取表達式
          stmt = conn.createStatement();
          //4. 執行SQL
          String sql = "select time from shijian where id=123";
          rs = stmt.executeQuery(sql);
          //5. 現實結果集里面的數據
          while(rs.next()) {
          System.out.println("id為123的time值=" + rs.getString(1));
          }
          }
          catch (Exception ex) {
          ex.printStackTrace();
          }
          finally {
          try {
          if(rs != null) {
          rs.close();
          }
          if(stmt!= null) {
          stmt.close();
          }
          if(conn != null) {
          conn.close();
          }
          } catch(Exception ex) {
          ex.printStackTrace();
          }
          }
          }
          }

          posted @ 2011-04-26 00:38 haojinlian 閱讀(138) | 評論 (0)編輯 收藏

          URL對象的創建及使用 URL類中一些很基本的方法

          URL類中一些很基本的方法如下:

          ·  public final Obect getContent() 這個方法取得傳輸協議。

          ·  public String getFile() 這個方法取得資源的文件名。

          ·  public String getHost() 這個方法取得機器的名稱。

          ·  public int getPort() 這個方法取得端口號。

          ·  public String getProtocol() 這個方法取得傳輸協議。

          ·  public String toString() 這個方法把URL轉化為字符串。

          實例:URL對象的創建及使用

          import java.net. *;
          import java.io.*;
          class Myurl  {
          public static void main(String args[])   {
             try {
              URL url=new URL("http://www.tsinghua.edu.cn/chn/index.htm");
              System.out.println("the Protocol: "+url.getProtocol());
              System.out.println("the hostname: " +url.getHost());
              System.out.println("the port: "+url.getPort());
              System.out.println("the file:"+url.getFile());
          System.out.println(url.toString());
          }catch(MalformedURLException e) {
          System.out.println(e);
               }
              }

          }

          posted @ 2011-04-21 19:50 haojinlian 閱讀(1070) | 評論 (0)編輯 收藏

          取得主機名和ip地址字符串

          import java.net.*;
          import java.io.*;
          class host {
          public static void main(String args[]) {
          try {
          InetAddress inetadd;
          inetadd=InetAddress.getLocalHost();
          System. out. println("hostname="+inetadd.getHostName());//取得主機名
          System. out. println(inetadd.toString() );//取得主機名和ip地址字符串
          }
          catch(Exception e) {
          System.out.println(e);
          }
          }
          }

          posted @ 2011-04-21 19:27 haojinlian 閱讀(183) | 評論 (0)編輯 收藏

          僅列出標題
          共3頁: 上一頁 1 2 3 下一頁 
          主站蜘蛛池模板: 洛川县| 石河子市| 无为县| 涞源县| 定日县| 邛崃市| 宿迁市| 金昌市| 桐乡市| 微山县| 兴仁县| 久治县| 丰宁| 晋州市| 峨山| 大化| 子长县| 麟游县| 荆州市| 璧山县| 龙游县| 和硕县| 额敏县| 沾化县| 大安市| 林周县| 大理市| 谢通门县| 偃师市| 新宁县| 孟村| 高雄县| 马尔康县| 临清市| 景宁| 博爱县| 木兰县| 沐川县| 虹口区| 安阳县| 喀什市|