deleting
My Java link database, and the toolkit used for adding, deleting, checking and modifying – source code_MySQL-mysql tutorial
package com.msit.util; import java.sql.Connection;import java.sql.DriverManager;import java.sql. PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement; /** * Database tool class link MySql database * * @author Administrator * */public class SqlHelper { // Data required for the link (these data are written directly to the encrypted data file ). private static String url = “jdbc:mysql://127.0.0.1:3306/msitdb”; private static String user = “root”; private static String password = “root”; private static String driverName = “com.mysql.jdbc.Driver”; // Declare a static link object private static Connection cOnnection= null; // Write a static code block (than The constructor is loaded first) is used to load the driver class static { try { Class.forName(driverName); } catch (ClassNotFoundException e) { e.printStackTrace(); } } public static Connection getConnection() { // Create a link object try { cOnnection= DriverManager.getConnection(url, user, password); } catch (SQLException e) { e.printStackTrace(); } return connection; } /** * Execute add and delete Modified sql statement method * * @param sql * @return number of affected rows */ public static int executeNotQuery(String sql) { int num = 0 ; // 1. Get the link object Connection cOnn= getConnection(); // 2. Create the command execution object Statement stm = null; try { stm = conn.createStatement(); num = stm.executeUpdate(sql); } catch…
My Java link database, and the toolkit used for adding, deleting, checking and modifying – source code_MySQL
package com.msit.util; import java.sql.Connection;import java.sql.DriverManager;import java.sql. PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement; /** * Database tool class link MySql database * * @author Administrator * */public class SqlHelper { // Data required for the link (these data are written directly to the encrypted data file ). private static String url = “jdbc:mysql://127.0.0.1:3306/msitdb”; private static String user = “root”; private static String password = “root”; private static String driverName = “com.mysql.jdbc.Driver”; // Declare a static link object private static Connection cOnnection= null; // Write a static code block (than The constructor is loaded first) is used to load the driver class static { try { Class.forName(driverName); } catch (ClassNotFoundException e) { e.printStackTrace(); } } public static Connection getConnection() { // Create a link object try { cOnnection= DriverManager.getConnection(url, user, password); } catch (SQLException e) { e.printStackTrace(); } return connection; } /** * Execute add and delete Modified sql statement method * * @param sql * @return number of affected rows */ public static int executeNotQuery(String sql) { int num = 0 ; // 1. Get the link object Connection cOnn= getConnection(); // 2. Create the command execution object Statement stm = null; try { stm = conn.createStatement(); num = stm.executeUpdate(sql); } catch…
Adding, deleting, modifying, and checking arrays of JavaScript study notes_javascript skills
The importance of arrays in programming languages is self-evident. Arrays in Javascript are also one of the most commonly used objects. Arrays are ordered collections of values. Due to weak types, arrays in Javascript are very flexible and powerful. Unlike Arrays in strongly typed high-level languages such as Java can only store elements of the same type or its subtypes. Javascript can store multiple types of elements in the same array, and the length can also be dynamically adjusted, and can be automatically adjusted as the data increases or decreases. Change the array length. Array is a common object in Javascript. It has some classic operations, such as adding, deleting, modifying and searching the array. This article mainly summarizes the relevant operation methods in this regard. Add array items First, let’s look at how to add array items to an array. Suppose there is an array: var arr = []; An array is declared above, but this array is an empty array [] with a length value of 0. Next we look at how to add array items to the array arr. The simplest way is to add array items to the array through index values: var arr = [];…
A simple example of dynamically adding, moving, deleting, selecting all and other operations in a multi-select list box_javascript skills
The code is as follows: <%dim aa = split (Request.Form(“sourceList”),”,”)Response.Write “Source:” & Request.Form(“sourceList”) & ubound(a) & “Object:” & Request.Form (“objectList”) & ““%> 1 2 3 <% for i = 6 to 20 Response.Write(“” & i+200 & “” & vbcrlf) Next %> 1 4 5 <% for i = 6 to 20 Response.Write(“” & i & “” & vbcrlf) Next %>
JavaScript methods to implement adding, deleting, and sorting data in drop-down list boxes
The example in this article describes the Javascript method of adding, deleting, and sorting data in a drop-down list box. Share it with everyone for your reference. The details are as follows: Here we implement the operations of adding, deleting, moving up and down data items in a drop-down list box that supports multiple selections. We often see this function on some talent websites or programming technology stations, which is more practical. . The screenshot of the running effect is as follows: The specific code is as follows: ASP PHP ASP.NET JAVA DELPHI I hope this article will be helpful to everyone’s Javascript programming design.
Detailed explanation of the code for adding, deleting, modifying and checking functions in the SSM framework in Java
Record the steps of integrating the smm framework for the first time. Reference blogs and websites include: I Don’t Have Three Hearts How2J Learning Website 1. The database uses mySql. First create the database ssm1 and create the table student create database ssm1; use ssm1; CREATE TABLE student( id int(11) NOT NULL AUTO_INCREMENT, student_id int(11) NOT NULL UNIQUE, name varchar(255) NOT NULL, age int(11) NOT NULL, sex varchar(255) NOT NULL, birthday date DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 2. Create a new java web project, name it ssm1, and import the relevant jar package. 3. Create a pojo class, named student here, and the package name is com.ssm1.pojo package com.ssm1.pojo; public class Student { private int id; private int student_id; private String name; private int age; private String sex; private String birthday; public int getId() { return id; } public void setId(int id) { this.id = id; } public int getStudent_id() { return student_id; } public void setStudent_id(int student_id) { this.student_id = student_id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public…
Java implementation method of adding, deleting, modifying and checking xml node attributes
Before studying this article, please read my other article JAVA’s operation of XML nodes to have a better understanding of XML operations. package vastsum; import java.io.File; import java.io.FileWriter; import java.util.Iterator; import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter; import org.junit.Test; /** * Use dom4j to operate xml * Manipulate xml attributes * Time: October 2, 2016 * The operation xml file is contact.xml * The file name of this file is: attrDemo.java * @author shutu008 * */ public class attrDemo{ @Test public void exmple() throws Exception{ //Read the XML file and obtain the document object SAXReader reader = new SAXReader(); Document document = reader.read(new File(“./src/contact.xml”)); //Get the attribute object of a node Element rootElem = document.getRootElement(); //Get the root node attribute object Attribute rootAttr = rootElem.attribute(“id”); //Get the specified node attribute object Element cOntactElem= rootElem.element(“contact”); Attribute cOntactAttr= contactElem.attribute(“id”); //Traverse all attributes of a node for (Iterator it = contactElem.attributeIterator();it.hasNext();){ Attribute cOnAttr= (Attribute)it.next(); String cOnTxt= conAttr.getValue(); String cOnAttrName= conAttr.getName(); System.out.println(conAttrName+” = “+conTxt); } //Set the attributes and values of a node contactElem.addAttribute(“name”, “zhangsan”); //Set (change) the value of an attribute Attribute nameAttr = contactElem.attribute(“name”); nameAttr.setValue(“lisi”); //Delete the specified attribute of a node contactElem.remove(nameAttr); //Write the attributes and values of…
Java implementation example of adding, deleting, modifying and checking cookies
COOKIE PROPERTIES name: name of COOKIE value: COOKIE value maxAge: COOKIE expiration time, the default is -1 value Description Negative numbers Invalid immediately after closing the browser 0 Clear COOKIE now Positive numbers Set the expiration time in seconds path The valid path of COOKIE, / indicates that this path can access the COOKIE under this project. If the path is not set, only the COOKIE path and its sub-paths can be accessed. GET ALL COOKIES public static COOKIE[] GetCOOKIEs(HttpServletRequest request){ return request.getCOOKIES(); } Obtaining COOKIE is very simple, just get it directly from the request. Get the specified COOKIE based on the name public static COOKIE getCOOKIEByName(HttpServletRequest request, String name) { if (StringUtils.isBlank(name)) { return null; } COOKIE[] COOKIEs = getCOOKIEs(request); if (null != COOKIES) { for (COOKIE COOKIE : COOKIES) { if (name.equals(COOKIE.getName())) { return COOKIE; } } } return null; } ADD COOKIE public static boolean addCOOKIE(HttpServletResponse response, String name, String value, int maxAge) { if (StringUtils.isBlank(name) || StringUtils.isBlank(value)) { return false; } COOKIE COOKIE = new COOKIE(name.trim(), value.trim()); if (maxAge <= 0) { maxAge = Integer.MAX_VALUE; } COOKIE.setMaxAge(maxAge); COOKIE.setPath("/"); response.addCOOKIE(COOKIE); return true; } DELETE COOKIE public static boolean removeCOOKIE(HttpServletRequest request, HttpServletResponse response, String name) { if…
Example of adding, deleting, modifying and checking XML files using Java
The example in this article describes the operations of adding, deleting, modifying and checking XML files in Java. Share it with everyone for your reference, the details are as follows: xml file: Harry Potter 10 This is a very nice book. Romance of the Three Kingdoms 10 One of the four great classics. Water Margin 6 One of the four great classics. Red Mansion 5 One of the four great classics. Add, delete, modify and check Test.java import java.io.File; import java.io.FileOutputStream; import org.w3c.dom.*; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.*; import javax.xml.xpath.*; public class Test { public static void main(String[] args) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Element theBook = null, theElem = null, root = null; try { factory.setIgnoringElementContentWhitespace(true); DocumentBuilder db = factory.newDocumentBuilder(); Document xmldoc = (Document) db.parse(new File(“Test.xml”)); root = xmldoc.getDocumentElement(); // — Start a new book —- theBook = xmldoc.createElement(“book”); theElem = xmldoc.createElement(“name”); theElem.setTextContent(“New Book”); theBook.appendChild(theElem); theElem = xmldoc.createElement(“price”); theElem.setTextContent(“20”); theBook.appendChild(theElem); theElem = xmldoc.createElement(“memo”); theElem.setTextContent(“The new book looks better.”); theBook.appendChild(theElem); root.appendChild(theBook); System.out.println(“— Start a new book —-“); output(xmldoc); // — Create a new book and complete —- // — Here are some modifications to “Harry Potter”. —- // — Query to find “Harry Potter”—- theBook = (Element)…
Detailed explanation of dynamically adding, deleting, modifying and checking attributes when converting Java objects to JSON
1. Introduction JSON processing is indispensable in daily development, and the need to add additional fields or delete specific fields in JSON is indispensable. Today we will use the Jackson class library to implement this function. 2. Add additional fields to JSON string Suppose we have JSON with this structure: { “username”:”felord.cn”, “age”:18 } Expect to add a gender field gender: { “username”: “felord.cn”, “age”: 18, “gender”: “male” } First use ObjectMapper to load the JSON string for ObjectNode: ObjectNode jsOnNodes= objectMapper.readValue(json, ObjectNode.class); ObjectNode provides many methods for manipulating JSON properties: get obtains the corresponding JsonNode based on the index or field name. The put series of methods provide the ability to add basic types, null values, objects, arrays, and primitive values to JSON. We can use the put method to add additional fields, complete code snippet: String json = “{\n” + ” \”username\”:\”felord.cn\”,\n” + ” \”age\”:18\n” + “}”; ObjectMapper objectMapper = new ObjectMapper(); ObjectNode jsOnNodes= objectMapper.readValue(json, ObjectNode.class); jsonNodes.put(“gender”, “male”); String newJson = objectMapper.writeValueAsString(jsonNodes); // newJson = {“username”:”felord.cn”,”age”:18,”gender”:”male”} 3. Add new fields when converting objects to JSON Sometimes the object we define does not contain specific fields, but additional fields are also needed when converting to JSON. Similar to Chapter…