jsp中有关连接数据库的问题,与PreparedStatement的用法?下面这串代码,能解释下吗?谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/10 00:24:54
<%
String DBDRIVER="org.gjt.mm.mysql.Driver";
String DBURL="jdbc:mysql://localhost:3306/sshuser=root&password=root&useUnicode=true&characterEncoding=gbk";
PreparedStatement pstmt=null ResultSet rs=null;
%>
<%
try
{
Class.forName(DBDRIVER) ;
Connection conn = DriverManager.getConnection(DBURL) ;
String sql = "SELECT id,uid,name,password FROM person" ;
pstmt = conn.prepareStatement(sql) ;
rs = pstmt.executeQuery() ;
%>

PreparedStatement是执行预编译的一个类,也就是先把SQL语句格式发送到数据库,然后填充里面的参数。
<%
String DBDRIVER="org.gjt.mm.mysql.Driver"; //数据库驱动
String DBURL="jdbc:mysql://localhost:3306/sshuser=root&password=root&useUnicode=true&characterEncoding=gbk"; //URL
PreparedStatement pstmt=null ResultSet rs=null;
%>
<%
try
{
Class.forName(DBDRIVER) ; //加载驱动
Connection conn = DriverManager.getConnection(DBURL) ; //获得连接
String sql = "SELECT id,uid,name,password FROM person" ;
pstmt = conn.prepareStatement(sql) ; //向数据库发送sql语句
rs = pstmt.executeQuery() ; //执行查询语句
%>