One, the code is as follows
private void Insert_mysql () {//TODO auto-generated method Stubjava.sql.PreparedStatement PS = null;java.sql.connection C n = 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 ");p s = cn.prepareStatement (" Insert into user (username, password, phone, email) VALUES (?,?,?,?); "); Ps.setstring (1, "WJB");p s.setstring (2, "WJB");p s.setstring (3, "WJB");p s.setstring (4, "WJB"); int i= Ps.executeupdate ( ); System.out.println (i); if (i>=1) {System.out.println ("NEW: Success");} else {System.out.println ("NEW: Failed");}} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();} finally {try {ps.close (); Cn.close ();} catch ( SQLException e) {e.printstacktrace ();}}}
private void Insert_mysql_two () {//TODO auto-generated method stubjava.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 ");p s = 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 ("NEW: Success");} else {System.out.println ("NEW: Failed");}} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();} finally {try {ps.close (); Cn.close ();} catch ( SQLException e) {e.printstacktrace ();}}}
MySQL database __jdbc direct Operation __preparedstatement__insert