Linux-jsp-jdbc-mysql Test-Insert

Source: Internet
Author: User
Tags insert mysql client linux
Js|mysql <%--
Author: He Zhiqiang [hhzqq@21cn.com]
Date: 2000-08-04
Function: Linux-jsp-jdbc-mysql test-Insert
--%>

<%
Statement
Java.sql.Connection sqlconn;//Database Connection objects
Java.sql.Statement sqlstmt;//Statement Object
Java.lang.String strname;//data from the client: name
Long lngage;//data from the client: Age

Registering JDBC Drivers
Class.forName ("Org.gjt.mm.mysql.Driver"). newinstance ();

Connecting to a database
Sqlconn = Java.sql.DriverManager.getConnection ("Jdbc:mysql://localhost/test", "Test", "test");

To create a statement object
sqlstmt = Sqlconn.createstatement ();

Get data from the client
StrName = Request.getparameter ("name");
Lngage = Java.lang.Long.parseLong (Request.getparameter ("Age"), 10);

Execute SQL statement
Sqlstmt.executeupdate ("INSERT into Test (name,age) VALUES (' +strname+" ', "+lngage+") ");

Close Statement Object
Sqlstmt.close ();

To close a database connection
Sqlconn.close ();
%>

<jsp:forward page= "select.jsp"/>


Related Article

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.