jdbc使用druid的工具类小案例
作者:互联网
实现查询
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
//使用druid的工具类实现查询
public class JDBCdemo10 {
public static void main(String[] args) {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
//获取连接对象
connection = JDBCUntils.getConnection();
String sql = "select * from student";
preparedStatement = connection.prepareStatement(sql);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()){
String name = resultSet.getString("name");
int age = resultSet.getInt("age");
System.out.println(name+": "+age);
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}finally {
JDBCUntils.close(connection,preparedStatement,resultSet);
}
}
}
标签:jdbc,java,resultSet,druid,connection,preparedStatement,sql,import,类小 来源: https://www.cnblogs.com/codegzy/p/14731905.html