Org. gjt. mm. mysql. the Driver is com. mysql. jdbc. driver's predecessor, if your project uses org. gjt. mm. mysql. driver, only for compatibility. It is no different from com. mysql. jdbc. Driver.
However, we recommend that you use com. mysql. jdbc. Driver for your current project. The following is the test code:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 27 28 29 30 |
Package com. evan. jdbc. test; import java. SQL. connection; import java. SQL. driverManager; import java. SQL. preparedStatement; import java. SQL. resultSet; public class JDBCdRIVERtEST {public static void main (String [] args) throws Exception {Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; String url = "jdbc: mysql: // localhost: 3306/evan "; String username =" root "; String password =" root "; String SQL =" select * from user "; // String className = "org. gjt. mm. mysql. driver "; String className =" com. mysql. jdbc. driver "; Class. forName (className); conn = DriverManager. getConnection (url, username, password); ps = conn. prepareStatement (SQL); rs = ps.exe cuteQuery (); while (rs. next () {System. out. println ("values in the user table" + rs. getString ("name "));}}} |