Java的JDBC的练习一
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class JDBC03 {
public static void main(String[] args) throws SQLException {
Statement stm=null;
Connection con=null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String sql="insert into account values(3,'王五',3000)";
con=DriverManager.getConnection("jdbc:mysql:///hsp_db02","root","011012");
stm=con.createStatement();
int count=stm.executeUpdate(sql);
System.out.println(count);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}finally {
if(stm!=null){
try{
stm.close();
}catch (SQLException e){
e.printStackTrace();
}
}
if(con!=null){
try{
con.close();
}catch (SQLException e){
e.printStackTrace();
}
}
}
}
}