日期:2014-05-18 浏览次数:20622 次
public JDBCTest(){
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://127.0.0.1:3306/car";
String user = "root";
String password = "root";
try
{
Class.forName(driver);
this.conn = DriverManager.getConnection(url, user, password);
if(!this.conn.isClosed())
System.out.printf("");
}
catch(ClassNotFoundException e)
{
System.out.println("Sorry,can`t find the Driver!");
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public float getCO2(){
try
{
String sql="select co2 from co2 where id=(select max(id) from co2)";
Statement statement = this.conn.createStatement();
ResultSet rs = statement.executeQuery(sql);
float i=0;
while(rs.next())
i=rs.getFloat("co2");
rs.close();
this.conn.close();
return i;
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
return 0;
}
public float get