import java.sql.*;
/**
 * 第一个 JDBC 的 HelloWorld 程序, 数据库访问 MySQL.
 * 
 * @author xiewenxuan520@126.com
 * @version 0.4 2012-01-31
 */
public class TestJDBC {
public static void main(String[] args) {
Connection conn = null; // 数据库连接
Statement stmt = null;  //数据库表达式
ResultSet rs = null;    //结果集
// 1. 注册驱动
try {
Class.forName("com.mysql.jdbc.Driver");//驱动注册
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
// 2. 获取数据库的连接
conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
"root","mysql");// root是用户名,密码为mysql
System.out.println("数据库连接成功");
// 3. 获取表达式
stmt = conn.createStatement();
// //执行插入数据
int row = stmt.executeUpdate("insert into student(id,name,age) values" +
"('14','张1三' , 20)");
System.out.println("插入了 " + row);
// 4. 执行 SQL
rs = stmt.executeQuery("select * from student");
// 5. 显示结果集里面的数据
while(rs.next()){
System.out.println("学生编号=" + rs.getString("id"));//打印输出信息
System.out.println("学生姓名=" + rs.getString("name"));
System.out.println("学生性别=" + rs.getString("age"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
conn.close();//关闭数据库连接
} catch (SQLException e) {
e.printStackTrace();
}
try {
stmt.close();//关闭连接
} catch (SQLException e) {
e.printStackTrace();
}
try {
rs.close();//关闭结果集连接
} catch (SQLException e) {
e.printStackTrace();
}
}
}

}

数据库:
test 
student
字段:
id,name,age