package com.cqust;
import com.cqust.utils.JDBCUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class JDBCUtilTest {
public static void main(String[] args) throws Exception {
Connection connection = JDBCUtil.getConnection();
String sql = “select empno,ename,sal,deptno from emp where ename like ?”;
PreparedStatement ps = connection.prepareStatement(sql);
ps.setString(1,”_A%”);
ResultSet resultSet = ps.executeQuery();
while (resultSet.next()){
String empno = resultSet.getString(“empno”);
String ename = resultSet.getString(“ename”);
String sal = resultSet.getString(“sal”);
String deptno = resultSet.getString(“deptno”);
System.out.println(empno+” “+ename+” “+sal+” “+deptno);
}
JDBCUtil.closeAllResources(connection,ps,resultSet);
}
}
Original: https://www.cnblogs.com/journeyhch/p/15575566.html
Author: journeyhch
Title: jdbc-使用工具类
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/599143/
转载文章受原作者版权保护。转载请注明原作者出处!