This year since the beginning of the AS3 development, feel more and more distant from Java, even the basic connection database to check the information ... Do not say, learn an article yourself.
Download and install MySQL before development, installation method: Http://www.duote.com/tech/1/2430_1.html
Once installed, the database can be developed using myeclipse or IntelliJ idea. But before you connect to the database, you need to have a database driver, which is the Java jar package.
You can download the Java MySQL driver package here: http://download.csdn.net/detail/weierbufan/8396207
1. Import the database driver:
Open Eclipse, create a project (my),
Action: Right-click my--->build Path--->add external archiver ... Select the JDBC driver and click OK.
In the list of items you can see:
2, verify that the database is not already connected available. The procedure is as follows:
ImportJava.sql.*; Public classTestjdb { Public Static voidMain (String args[]) {Try{class.forname ("Com.mysql.jdbc.Driver");//load MySQL JDBC driver//class.forname ("Org.gjt.mm.mysql.Driver");System.out.println ("Success Loading Mysql driver!"); } Catch(Exception e) {System.out.print ("Error Loading Mysql driver!"); E.printstacktrace (); } Try{Connection Connect=Drivermanager.getconnection ("Jdbc:mysql://localhost:3306/tx", "root", "126"); //connection URL is jdbc:mysql//server address/database name, the following 2 parameters are login username and password, respectivelySystem.out.println ("Success Connect Mysql server!"); Statement stmt=connect.createstatement (); ResultSet RS= Stmt.executequery ("SELECT * from MyClass"); while(Rs.next ()) {System.out.println (Rs.getint (1) + "\ T" +rs.getstring (2) + "\ T" +rs.getint (3) + "\ T" +rs.getdouble (4) + "\ T" +rs.getint (5)); } } Catch(Exception e) {System.out.print ("Get Data error!"); E.printstacktrace (); } }}
Running the above program will see the following results:
Indicates that the database has been successfully connected.
Eclipse connection to MySQL database