Flex+blazeds realizes the connection with MySQL database

Source: Internet
Author: User
Tags mysql table name mysql database

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 ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.