Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1073967
  • 博文数量: 252
  • 博客积分: 4561
  • 博客等级: 上校
  • 技术积分: 2833
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-15 08:23
文章分类

全部博文(252)

文章存档

2015年(2)

2014年(1)

2013年(1)

2012年(16)

2011年(42)

2010年(67)

2009年(87)

2008年(36)

分类: Java

2009-10-28 09:27:22

首先下载 mysql-connector-java-5.1.10-bin.jar


package comm;

import java.sql.*;

public class ConnectMysql
{
    public static void main(String args[]) throws Exception
    {
        Connection con = null;
        Statement sm = null;
        ResultSet rs = null;
        
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        
        String url = "jdbc:mysql://127.0.0.1/test";
        
        con = DriverManager.getConnection(url, "root", "123456");
        sm = con.createStatement();
        rs = sm.executeQuery("select * from fan");
        while (rs.next())
        {
            System.out.println(rs.getString("name"));
        }
        
        if (rs != null)
            rs.close();
        if (sm != null)
            sm.close();
        if (con != null)
            con.close();
    }
}


阅读(877) | 评论(0) | 转发(0) |
0

上一篇:mkdir递归创建多层目录

下一篇:struts example

给主人留下些什么吧!~~