Just learning flex soon, this little example passes through the RemoteObject communication method. To achieve flex and MySQL database interaction.
1 using the test database in MySQL, the table name is admin. field in table: ID username userpwd
(Ultimate goal: To display the records in a database table at the end of the flex-side Dategrid component)
2 Establishment of MyEclipse project. New->web project enters the project name. You will need to paste the downloaded BlazeDS package into the engineering directory. And put the MySQL driver in the project directory Lib folder
(I use version blazeds_turnkey_3-0-0-544.zip.) The unpacked folder will be changed to the Blazeds.war of the RAR, and decompression, will get the Meta-inf and Web-inf two folders into the newly built project under Webroot)
3 Writing Method Connectionhelper.java
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import java.sql.SQLException;
public class Connectionhelper
{
Private String URL;
private static Connectionhelper instance;
Private Connectionhelper ()
{
try {
Class.forName ("Com.mysql.jdbc.Driver");
url = "Jdbc:mysql://localhost/test";
catch (Exception e) {
E.printstacktrace ();
}
}
public static Connection getconnection () throws SQLException {
if (instance = = null) {
Instance = new Connectionhelper ();
}
try {
Return Drivermanager.getconnection (Instance.url, "root", "root");
catch (SQLException e) {
Throw e;
}
}
public static void Close (Connection Connection)
{
try {
if (connection!= null) {
Connection.close ();
}
catch (SQLException e) {
E.printstacktrace ();
}
}
}