1.在项目中导入java.sql包
2.加载数据库驱动程序Class.forName(“com.mysql.jdbc.Driver”);3.定义数据库的链接地址String url=“jdbc:mysql://localhost:3306/idea?characterEncoding=utf-8”;String useeName=“root”;String userPwd=“123456”; 4.得到与数据库的连接对象Connection conn=DriverManager.getConnection(url, userName, userPwd);5.声明sql语句select * from Good where goodId=?;6.得到语句对象PrepareStatement pst=null;ResultSet rs=null;
7.执行sql语句pst=conn.prepareStatement(sql);
rs=pst.executeQuery();8.处理sql语句的返回结果9.关闭对象