标签:enc drive update utf8 state rate new tco exec
private void insert_Mysql() { // TODO Auto-generated method stub java.sql.PreparedStatement ps = null; java.sql.Connection cn = null; ResultSet rs = null; try { // Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Class.forName("com.mysql.jdbc.Driver").newInstance(); cn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/learn?user=root&password=&useUnicode=true&characterEncoding=UTF8"); ps = cn.prepareStatement("insert into user(username, password, phone, email) values(?, ?, ?, ?);"); ps.setString(1, "wjb"); ps.setString(2, "wjb"); ps.setString(3, "wjb"); ps.setString(4, "wjb"); int i= ps.executeUpdate(); System.out.println(i); if(i>=1) { System.out.println("新增:成功"); }else { System.out.println("新增:失败"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { ps.close(); cn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
private void insert_Mysql_Two() { // TODO Auto-generated method stub java.sql.PreparedStatement ps = null; java.sql.Connection cn = null; ResultSet rs = null; try { // Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Class.forName("com.mysql.jdbc.Driver").newInstance(); cn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/learn?user=root&password=&useUnicode=true&characterEncoding=UTF8"); ps = cn.prepareStatement("insert into user(username, password, phone, email) values(‘332‘, ‘332‘, ‘33‘, ‘322‘);"); int i= ps.executeUpdate(); System.out.println(i); if(i>=1) { System.out.println("新增:成功"); }else { System.out.println("新增:失败"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { ps.close(); cn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
mysql数据库__Jdbc直接操作__PreparedStatement__insert
标签:enc drive update utf8 state rate new tco exec
原文地址:http://www.cnblogs.com/wujianbo123/p/7637037.html