我想在将值传递给参数时创建一个方法,它将传递给 sql 语句。这是我尝试过的:
import java.sql.*;
import java.util.*;
import java.text.*;
public class cobadatabase{
protected String sn,fn,ln;
private Connection conn;
private PreparedStatement st;
public cobadatabase(String studentnumber)
{
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/studentrecords","root","");
st = conn.prepareStatement("SELECT * FROM student WHERE Student_Number=?");
ResultSet rs = st.executeQuery();
while (rs.next()){
sn = rs.getString(1);
fn = rs.getString(2);
ln = rs.getString(3);
SimpleDateFormat ft = new SimpleDateFormat("kk:mm:ss");
ft.format(rs.getTime("Total Time").getTime());
}
}
catch(Exception e){
e.printStackTrace();
}
我不知道我的代码有什么问题。我只想检索数据以进行打印