数据库插入操作
时间:2021-07-01 10:21:17
帮助过:9人阅读
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 }
数据库插入操作
标签:span val create static stat pre man str void