mysql数据库的连接

时间:2023-03-09 01:24:54
mysql数据库的连接
public TJb checkjbByschool(long id)throws ClassNotFoundException,SQLException {
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1/sql", "user1", "11111111");
Statement statement = connection.createStatement();
ResultSet resultSet;
String s = "select * from tjb "
+ "where time=(select max(time) from tjb where school ="+school_id+" ) "
+ "and school="+school_id;
resultSet = statement.executeQuery(s);
if (resultSet.next())
{
TJb jb = (TJb)jbRepository.findOne(resultSet.getLong("id"));
/**数据库关闭链接**/
connection.close();
return jb;
}
else {
/**数据库关闭链接**/
connection.close();
return null;
}
}