//此连接是针对于mysql的连接
public class MybatisJdbcConnection {
public static void main(String[] args){
Connection conn = null;
ResultSet res = null;
PreparedStatement prepareStatement=null;
try {
//加载数据库驱动
Class.forName(“com.mysql.jdbc.Driver”);
//获得数据库连接池
conn = DriverManager.getConnection(“jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf-8”, “root”, “root”);
//定义sql语句
String sql = “select * from user where username = ?”;
//得到预处理statement
prepareStatement = conn.prepareStatement(sql);
//设置参数,?代表的是需要查询的条件也就是参数从1开始,有几个就设置几个
prepareStatement.setString(1, “王五”);
//向数据库发出sql执行查
版权声明:本文为burtquan原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。