码迷,mamicode.com
首页 > 数据库 > 详细

mysql数据库的连接

时间:2015-08-13 15:41:24      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

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;
        }
    }

 

mysql数据库的连接

标签:

原文地址:http://www.cnblogs.com/leov/p/4727463.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!