Packagecom. mingxin. util; importjava. SQL. connection; importjava. SQL. driverManager; importjava. SQL. SQLException; importcom. mysql. jdbc. resultSet; importcom. mysql. jdbc. statement; publicclassConnectionUtils {privatestaticStringdrivercom
Package com. mingxin. util; import java. SQL. connection; import java. SQL. driverManager; import java. SQL. SQLException; import com. mysql. jdbc. resultSet; import com. mysql. jdbc. statement; public class ConnectionUtils {private static String driver = com
Package com. mingxin. util; import java. SQL. connection; import java. SQL. driverManager; import java. SQL. SQLException; import com. mysql. jdbc. resultSet; import com. mysql. jdbc. statement; public class ConnectionUtils {private static String driver = "com. mysql. jdbc. driver "; private static String url =" jdbc: mysql: // 127.0.0.1: 3306/db_mx "; private static String user =" root "; private static String password =" 123456"; Private static Connection conn = null; static {try {Class. forName (driver);} catch (ClassNotFoundException e) {System. out. println ("Driver loading failed .. "); e. printStackTrace () ;}} public static Connection getConnection () {try {conn = DriverManager. getConnection (url, user, password); if (! Conn. isClosed () {System. out. println ("Successed connecting to the Database... ") ;}} catch (SQLException e) {System. out. println ("database connection failed... "); e. printStackTrace ();} return conn;} public static void main (String [] args) {// getConnection (); try {Statement statement = (Statement) conn. createStatement (); String SQL = "select * from user"; ResultSet rs = (ResultSet) statement.exe cuteQuery (SQL); String email = null; String name = null; string phone = null; while (rs. next () {email = rs. getString ("u_email"); name = rs. getString ("u_name"); phone = rs. getString ("u_phone"); System. out. println ("u_email =" + email + "___ u_name =" + name + "____ phone =" + phone) ;}} catch (SQLException e) {e. printStackTrace ();}}}