mysql的retrieve
时间:2021-07-01 10:21:17
帮助过:27人阅读
import java.sql.*;public class retrieve { public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } String sql="SELECT * FROM hero ";//查询整个表的数据, select count(*) from hero 查询总数 select * from hero limit 0,5; 查询前五个数据 try (Connection c= DriverManager.getConnection("jdbc:mysql://localhost:3306/how2java?characterEncoding=utf-8", "root","123456"); //创建语句 PreparedStatement ps=c.prepareStatement(sql);){ ResultSet rs=ps.executeQuery(); while (rs.next()){ int id=rs.getInt(1); String name=rs.getString(2); float hp=rs.getFloat(3); int damage=rs.getInt(4); System.out.println(name); } } catch (SQLException e) { e.printStackTrace(); } }}mysql的retrieve
标签:odi port float tst string rman not stat coding