JDBC Common Memos

Source: Internet
Author: User

Jdbc

Contents of the JDBC Utils package

Performing a driver load in a static code block

Class.forName ("Com.mysql.jdbc.Driver");

Four private variables, which need to be modified when the database is different;

Private static final String username = "root";
Private static final String password = "root";
Private static final String URL = "Jdbc:mysql://localhost/mysql?seunicode=true&characterencoding=utf8";
private static final String drivername = "Com.mysql.jdbc.Driver";

Then encapsulated the ExecuteQuery (Connection conn,string sql,object...parameters)/executequery (sql,parameters)

Executeupdate (Connection conn,string sql,object...parameters)/executeupdate (sql,parameters)

and the corresponding close (conn/rs) method;

SQL additions and deletions change clause

SELECT * FROM table name

Select name from table name where conditional statement Name=value

Insert into table name (property name 1, property name 2 ...) values (attribute value 1, property value 2 ...);

Update table Name set Name=value, name2=value2 ... where condition statement;

Delete from table where Name=value

The total MySQL database Query method can be select COUNT (*) from  table (table name); Total: Select count as TotalCount from table1 summation: select sum (field1)  As Sumvalue from table1 average: Select AVG (field1) as Avgvalue from table1 maximum: select Max (field1) as MaxValue from table1 min: Select Min (field1) as MinValue from table1


Http://www.cnblogs.com/cunkouzh/p/5588319.html

JDBC Common Memos

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.