Package com.wangbingan.utils;import java.sql.connection;import java.sql.drivermanager;import  JAVA.SQL.RESULTSET;IMPORT JAVA.SQL.STATEMENT;/** * JDBC Linked Database * * @ author administrator * */public class jdbcutil {public static Void main (string args[]) throws Exception {// database connection connection conn = null;// Record database Data Int count = 0;// resultset object Resultset re = null ;// driver string drive = "com.mysql.jdbc.Driver";// address string url = "JDBC: Mysql://localhost:3306/shiro "+ "?username=root&password=root&useunicode=true& Characterencoding=utf8 ";// Load Database driver Class.forName (drive);// get database link conn = Drivermanager.getconnection (URL);// statement has three ways to execute SQL statement stmt = Conn.createstatement ();// query string sql = "SELECT&NBSp;* from vip ";// New string sql1 = " Insert into vip (Id, name, phone) values (' 3 ', ' 3 ', ' 3 ') ";// returns a Boolean value. Falseboolean result1 = stmt.execute ( SQL1);// Returns a Boolean value. Trueboolean result = stmt.execute (SQL);// updated number of bars INT RESULT2 = stmt.executeupdate (SQL1);// returns resultsetre = stmt.executequery (SQL);while ( Re.next ()) {system.out.println ("Query data ..." + "Name:" + re.getstring ("name") + "-" + "Tel:" + re.getstring ("Phone") + "\ n"); count++;} SYSTEM.OUT.PRINTLN ("Execute added successful return value:" + result1 + "\ n"); System.out.println ("Executeupdate added successful return value:" + result2 + "\ n");if (Result) { SYSTEM.OUT.PRINTLN ("Database total:" + count + "bar data" + "\ n");}}
Reference website:
The difference between JDBC execution SQL three methods: http://www.blogjava.net/yxhxj2006/archive/2012/08/01/384544.html
JDBC Link mysql:http://www.cnblogs.com/cy163/archive/2008/08/22/1274413.html
Summarize: JDBC performs a query operation, uses ExecuteQuery (), performs an update operation, uses execute (), or executeupdate ().
Supplement: JDBC Query bar number, not supported, so the execution uses the counter to calculate.
JDBC Link mysql database + Execute SQL