1 Connection con = null; 2 Statement stmt = null; 3 4 // 保存到表中 5 String sql = "insert into website(username,userpassw) values('喜欢','不喜欢')"; 6 7 try { 8 Class.forName("com.mysql.jdbc.Driver"); 9 //链接对象 10 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/mysqlconnect", "root", "bequt"); 11 //执行命令对象 12 stmt = con.createStatement(); 13 //执行 14 stmt.execute(sql); 15 //关闭 16 stmt.close(); 17 con.close(); 18 } catch (Exception e) { 19 // TODO Auto-generated catch block 20 e.printStackTrace(); 21 }