~ 数据库设计
package com.yanyu;
import com.sun.deploy.ui.AboutDialog;
import java.sql.*;
import java.util.ResourceBundle;
public class Demo01 {
public static void main(String[] args) throws ClassNotFoundException {
// 读取属性文件
ResourceBundle bundle = ResourceBundle.getBundle("com\\yanyu\\db");
String driver = bundle.getString("driver");
String user = bundle.getString("user");
String password = bundle.getString("password");
String url = bundle.getString("url");
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try{
Class.forName(driver);
con = DriverManager.getConnection(url,user,password);
con.setAutoCommit(false);
String sql = "insert into user(name,password) values(?,?) ";
ps = con.prepareStatement(sql);
// ? 告诉系统 ? 是什么
ps.setString(1,"烟雨");
ps.setString(2,"123");
// 执行
ps.execute();
con.commit();
}catch (ClassNotFoundException | SQLException e){
if (con != null){
try{
con.rollback();
}catch (SQLException throwables){
throwables.printStackTrace();
}
}
e.printStackTrace();
}finally {
// 关流 DBUtil.close(rs,ps,con);
}
}
}