Flash can show a wide range of visual effects and embodiment in terms of communication, but it is relatively weak in server technology, so it has to rely on other server technologies. Such as C ++ Java jsp php.
We hope to present a wide range of results in the client. here we can use flex as the client. It has rich components and has excellent results.
Okay, let's solve the following problems:
First, solve JSP connection to MySQL database
Second, how to call JSP to insert the data sent by the client to the database.
First, solve the first problem:
Connection con = NULL; </P> <p> try {</P> <p> class. forname ("com. mySQL. JDBC. driver "); <br/> string dburl =" JDBC: mysql: // localhost: 3306/test? Useunicode = true & characterencoding = gb2312 "; <br/> string dbuser =" root "; <br/> string dbpwd =" 123 "; <br/> con = drivermanager. getconnection (dburl, dbuser, dbpwd); <br/> out. print ("22 connected ..... "); </P> <p >}catch (exception ex) </P> <p >{</P> <p> out. Print (" Connection Failed !! <Br> "+ ex. tostring (); </P> <p>}
The username of MySQL is root, and password: 123 database name is test
Second, execute the database INSERT command:
<% @ Page contenttype = "text/html; charset = gb2312" Language = "Java" Import = "Java. SQL. * "errorpage =" "%> <br/> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "/> <br/> <title> untitled document </title> <br/> </pead> <br/> <body> <br/> <p> welcome here </P> <br/> <% <br/> string myname = request. getparameter ("username"); <br/> string Pwd = request. getparameter ("userpwd"); <br/> out. print (myname); <br/> out. print (PWD); <br/> connection con = NULL; </P> <p> try {<br/> class. forname ("com. mySQL. JDBC. driver "); <br/> string dburl =" JDBC: mysql: // localhost: 3306/test? Useunicode = true & characterencoding = gb2312 "; <br/> string dbuser =" root "; <br/> string dbpwd =" 123 "; <br/> con = drivermanager. getconnection (dburl, dbuser, dbpwd); <br/> out. print ("successfully connected"); <br/> string SQL = "insert into admin (username, userpwd) values ('" + myname + "', '"+ PWD +"') "; <br/> statement stmt = con. createstatement (resultset. type_scroll_insensitive, resultset. concur_read_only); <br/> stmt.exe cuteupdate (SQL); </P> <p >}< br/> catch (exception ex) <br/>{< br/> out. Print ("connection failed !! <Br> "+ ex. tostring (); <br/>}</P> <p >%> <br/> </body> <br/> </ptml> <br/>
The first is to receive two messages sent by the Client: username and userpwd. After receiving this field.
Create an admin table in MySQL to test whether the insert operation is successful?
Next, we use the SQL statement to insert to the admin table in the test data. The two fields are username and password userpwd, respectively.
String SQL = "insert into admin (username, userpwd) values ('" + myname + "', '" + PWD + "')"; <br/> statement stmt = con. createstatement (resultset. type_scroll_insensitive, resultset. concur_read_only); <br/> stmt.exe cuteupdate (SQL );
Such a simple insert operation is complete. With this foundation, we can try more effects, such as query and deletion.
(Note: The message sending function communicates with JSP 2 in as3.0)