安装mysql
navicat成功连接mysql
建立自己的数据表
成功创建和导入MAVEN文件并且显示数据库内容
package web.wust;
import java.sql.*;
public class WORK2 {
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection c = DriverManager
.getConnection(
"jdbc:mysql://localhost:3306/web?characterEncoding=UTF-8",
"root", "mysql");
Statement s = c.createStatement();
// 准备sql语句
// 注意: 字符串要用单引号'
String sql = "select * from work2";
ResultSet rs =s.executeQuery(sql);
while (rs.next()) {
System.out.println( rs.getString(2) );
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
显示第二列