package Java_JDBC;
import java.sql.*;
public class JDBC_Select {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://192.168.8.14:3306/day22_JDBC";
String user = "root";
String password = "123456";
Connection con = DriverManager.getConnection(url,user,password);
Statement st = con.createStatement();
String sql = "select * from sort";
ResultSet rs = st.executeQuery(sql);
System.out.println(rs);
while (rs.next()){
System.out.println(rs.getString("sid")+" "+rs.getString("sname")+" "+
rs.getString("sprice")+" "+rs.getString("sdesc"));
}
rs.close();
st.close();
con.close();
}
}
网友评论