public class JdbcNoarg {
//查询一行数据
public void getQueryNoargOne(){
JdbcMysqlPool jdbc = new JdbcMysqlPool()
Connection con=null
Statement st = null
String sql
ResultSet rst = null
try {
//获取数据库连接
con = jdbc.getConnection()
//在连接里打开一条通道createStatement,返回Statement对象
st = con.createStatement()
sql = "select *from student"
//把我们想要结果sql语句发送给数据库,数据库返回的数据用java ResultSet来接收
rst= st.executeQuery(sql)
//获取结果集的第一行数据9
rst.first()
//获取结果集指定列的数据
String name = rst.getString("name")
String interest = rst.getString("interest")
System.out.println("name:"+name+"interest:"+interest)
} catch (Exception e) {
e.printStackTrace()
}finally {
try {
if(rst!=null)
rst.close()
if(st!=null)
st.close()
if(con!=null)
con.close()
} catch (Exception e2) {
e2.printStackTrace()
}
}
}
SQL语句像这样SELECT t.* FROM student st JOIN teach t ON st.teach_id=t.id
WHERE st.studentNo=?
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)