JDBC Link mysql database + Execute SQL (MAC)

Source: Internet
Author: User
Tags stmt

Package com.wangbingan.jdbc;import java.sql.connection;import java.sql.drivermanager;import  java.sql.ResultSet;import java.sql.Statement;public class JdbcUtil {public  Static void main (string args[])  throws exception {connection conn =  null;//  Load Database driver Class.forName ("Com.mysql.jdbc.Driver");//  Get database connection try {conn =  Drivermanager.getconnection ("Jdbc:mysql://127.0.0.1:3307/test",  "root",  "Wangbingan");}  catch  (exception e)  {e.printstacktrace (); SYSTEM.OUT.PRINTLN ("Database link failed!");}  statement There are many ways to Statement stmt = conn.createstatement ();// sqlstring sql  =  "select * from best "; String sql1= " insert into best (Id,name,phone) VALUES (' 8 ', ' 3 ', ' 3 ')";//  Executive Sqlstmt.executeupdate (SQL1); Resultset result = stmt.executequery (SQL);while  (Result.next ())  {system.ouT.println (result.getstring ("id"));}}} 

Summarize:

    1. IP to be set to 127.0.0.1, the database should be consistent

    2. Database account, password, it must be remembered, not the right to start MySQL account, but in the installation of MySQL, set, generally is root, the password set itself (set, must remember!)

    3. The database port is 3307, not 3306

Resources:

LocalHost cannot access, 127.0.0.01 can access: http://www.webkaka.com/tutorial/server/2013/121611/

JDBC Link mysql database + Execute SQL (MAC)

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.