美文网首页
JDBC_Select

JDBC_Select

作者: 勇者与王者 | 来源:发表于2019-10-03 00:00 被阅读0次
    
    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();
        }
    }
    
    

    相关文章

      网友评论

          本文标题:JDBC_Select

          本文链接:https://www.haomeiwen.com/subject/nrarpctx.html