java连接ACCESS数据库(要设置数据源),如何查找并删除班级
发布网友
发布时间:2024-04-01 15:07
我来回答
共1个回答
热心网友
时间:2024-07-24 03:32
import java.sql.*;
import java.util.Scanner;
public class JdbcOdbc{
public static void main(String args[])throws SQLException{
Scanner sc = new Scanner(System.in);
System.out.print("请输入班级名:");
String clazz= sc.next();
String url="jdbc:odbc:class";
String user="sa";
String pass="123456";
Connection conn=DriverManager.getConnection(url, user, pass);
String sql="SELECT * FROM student WHERE class=?";
PreparedStatement st=conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
st.setString(1, clazz);
ResultSet rs=st.executeQuery();
while(rs.next()){
System.out.print(rs.getString(1));
rs.deleteRow();
}
rs.close();
st.close();
conn.close();
}
}