JDBC

JDBC是java数据库连接技术的简称。

PreparedStatement 与 Statement 的区别

java.sql包中的PreparedStatement 接口继承了Statement,并与之在两方面有所不同:有人主张,在JDBC应用中,如果你已经是稍有水平开发者,你就应该始终以PreparedStatement代替Statement.也就是说,在任何时候都不要使用Statement
 
JDBC访问数据库的步骤
1.导包
2.加载驱动类    Class.ForName("com.mysql.jdbc.Driver");
3.建立连接数据库   conn=DriverManger getConnection("jdbc:mysql://localhost:3306/myschool","root","root");
4. 执行SQL语句    conn=stat.prepareStatement(sql);
5.返回处理结果    rs=stat.executeQuery();
6.关闭结果      conn.close()
 
PreparedStatement注入  相当于原来是一个条件,现在是两个条件只能满足一个
select * from student where studentName=?
select *from student where studentName=?,1or2
 
 
 
原文地址:https://www.cnblogs.com/pan520/p/12974590.html