package Day29_JDBC.JDBC_Util;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* @Author quzheng
* @Date 2019/10/3 10:18
* @Version 1.0
* 使用JDBCUtil工具类
*/
public class JDBCUtilDemo {
public static void main(String[] args) throws SQLException {
Connection con = JDBCUtils.getConnection();
String sql = " select sname from sort";
PreparedStatement pst = con.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
while (rs.next()){
//这里无法获取到其他字段,因为只查了sname
System.out.println(rs.getString("sname"));
}
}
}
网友评论