1 package org.lxh.demo17.statementdemo; 2 3 import java.sql.Connection; 4 import java.sql.DriverManager; 5 import java.sql.Statement; 6 7 public class InsertDemo01 { 8 private static final String DBDRIVER = "com.mysql.jdbc.Driver"; 9 private static final String DBURL = "jdbc:mysql://localhost:3306/mldn"; 10 private static final String DBUSER = "root"; 11 private static final String DBPASS = "root"; 12 public static void main(String[] args) throws Exception { 13 Connection conn = null; 14 Statement stmt = null; 15 String sql = "insert into user(name,password,age,sex,birthday)"+ 16 "values('张三','www.mldn,cn',30,'男','2008-08-27')"; 17 Class.forName(DBDRIVER); 18 conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS); 19 stmt = conn.createStatement(); 20 stmt.executeUpdate(sql); 21 stmt.close(); 22 conn.close(); 23 } 24 25 }