//首先下载对应的mysql连接的jar包

import java.sql.*;//导入对应的包

String url = “jdbc:mysql://10.61.0.34:3308/soluckingdb2?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8″;
String user = “root”;
String password = “*****”;
try{
Class.forName(“com.mysql.jdbc.Driver”).newInstance();
//获得一个连接
conn = DriverManager.getConnection(url,user,password);
//生成一个句子
Statement stmt = conn.createStatement();
String sql = “select * from service”;
ResultSet res = stmt.executeQuery(sql);
while(res.next)
{
System.out.println(res.getString(“serviceName”));
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}

本文地址:http://www.yaronspace.cn/blog/index.php/archives/139

来自yaronspace.cn  本文链接:http://yaronspace.cn/blog/archives/139