[java]代码库
import java.sql.*;
public class SampleIntro
{
public static void main(String[] args)
{
try
{
Connection conn;
Statement stmt;
ResultSet res;
//加载Connector/J驱动
//这一句也可写为:Class.forName("com.mysql.jdbc.Driver");
Class.forName("com.mysql.jdbc.Driver").newInstance();
//建立到MySQL的连接
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
"root", "guapo");
//执行SQL语句
stmt = conn.createStatement();
res = stmt.executeQuery("select * from pet");
//处理结果集
while (res.next())
{
String name = res.getString("name");
System.out.println(name);
}
res.close();
}
catch (Exception ex)
{
System.out.println("Error : " + ex.toString());
}
}
中级程序员
by: token 发表于:2014-02-21 18:26:23 顶(0) | 踩(0) 回复
链接mysql的
回复评论