1, in fact, I found that with the skill of PHP in the inside, learning Java up or not very laborious, but Java has no process-oriented
Packagesecond;Importjava.sql.*;//Import Public classMySQL { Public Static voidMain (string[] args)throwssqlexception{String Driver= "Com.mysql.jdbc.Driver";//declaring the class to be importedString DSN = "Jdbc:mysql://127.0.0.1:3306/mysql";//DSNString user = "root";//Account nameString pass = "";//Password Try{class.forname (driver);//I think it should be equivalent to the new Class () in PHP;Connection conn = drivermanager.getconnection (DSN, user, pass);//instantiate a DB connection if(!conn.isclosed ()) {//if the link is not closed "can actually be understood as if the link succeeds"System.out.println ("link succeeded!")); } Statement Statement= Conn.createstatement ();//Create a statement objectString sql = "Select user,host from User";//SQL statementsResultSet rs = statement.executequery (SQL);//executes the sq statement and gets a resource result set while(Rs.next ()) {//loop, the pointer moves downString name = rs.getstring ("user");//nameString local= rs.getstring ("host");//Address } }Catch(ClassNotFoundException e) {//ExceptionSystem.out.println (E.getmessage ()); } }}
PS: It is worth noting that if you want to use MySQL, you have to first import the MySQL library,
Eclipse Import Method: Project Project-Properties->java Build path-add external jar