简单demo
import java.sql.Connection ;import java.sql.DriverManager ;import java.util.Scanner ;import java.sql.Statement ;class Tester{ public static final String DBDRIVER = "org.gjt.mm.mysql.Driver";public static final String DBURL = "jdbc:mysql://localhost:3306/student" ;public static final String DBUSER = "root" ;public static final String DBPASS = "include" ;public static void main(String args[]) throws Exception{ Connection con=null;Statement sta=null;Class.forName(DBDRIVER) ; Scanner sc=new Scanner(System.in) ;System.out.println("输入姓名"); String name=sc.next(); System.out.println("输入密码"); int password = sc.nextInt(); System.out.println("输入年龄"); int age=sc.nextInt(); System.out.println("输入性别"); String sex=sc.next(); System.out.println("输入生日"); String birthday = sc.next(); String sql="insert into user (name,password,age,sex,birthday)" + " values('"+name+"',"+password+","+age+",'"+sex+"','"+birthday+"')" ; //String sql = "INSERT INTO user(name,password,age,sex,birthday) "+//" VALUES ('"+name+"','"+password+"',"+age+",'"+sex+"','"+birthday+"')" ;con = DriverManager.getConnection(DBURL,DBUSER,DBPASS);sta=con.createStatement() ;sta.executeUpdate(sql);sta.close();sc.close();con.close();System.out.println("数据加入成功");}}