废话不多说,直接上代码
Connection conn; String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://127.0.0.1:3306/*****"; String user = "root"; String password = ""; try { //加载驱动程序 Class.forName(driver); conn = DriverManager.getConnection(url,user,password); if(!conn.isClosed()) System.out.println("Succeeded connecting to the Database!"); String sql = "UPDATE secret " + "SET appSecret = '"+appSecret+"',time = '"+time+"',timeSecret = '"+timeSecret+"' WHERE id = '1'"; Statement statement = conn.createStatement(); statement.executeUpdate(sql); conn.close(); } catch(ClassNotFoundException e) { //数据库驱动类异常处理 System.out.println("Sorry,can`t find the Driver!"); e.printStackTrace(); } catch(SQLException e) { //数据库连接失败异常处理 e.printStackTrace(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } finally { System.out.println("数据库数据成功输入!!"); }数据库名自己改一下