javabio代码示例 java代码怎么写
java递归查询子节点,按给的示例代码实现
代码如下:
创新互联公司专业为企业提供惠东网站建设、惠东做网站、惠东网站设计、惠东网站制作等企业网站建设、网页设计与制作、惠东企业网站模板建站服务,10多年惠东做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
import java.util.ArrayList;
import java.util.List;
class Org {
private String id;
private String name;
private String pid;
public Org(String id, String name, String pid) {
this.id = id;
this.name = name;
this.pid = pid;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPid() {
return pid;
}
public void setPid(String pid) {
this.pid = pid;
}
@Override
public String toString() {
return "Org [id=" + id + ", name=" + name + ", pid=" + pid + "]";
}
}
public class App {
static void find(ListOrg list, String pid) {
list.stream().filter(p - p.getPid().equals(pid))
.forEach(org - {
System.out.println(org);
find(list, org.getId());
});
}
public static void main(String[] args) {
ListOrg list = new ArrayList();
list.add(new Org("111", "公司", "0"));
list.add(new Org("222", "部门", "111"));
list.add(new Org("333", "小组", "222"));
list.add(new Org("444", "员工1", "333"));
list.add(new Org("555", "员工2", "333"));
find(list, "0");
System.out.println("------------------------------------");
find(list, "111");
}
}
运行结果:
java clob
java clob是什么,让我们一起了解一下?
CLOB是内置类型,将字符大对象存储为数据库表某一行中的一个列值。默认情况下,驱动程序使用SQL locator实现Clob对象,这意味着CLOB对象包含一个指向SQL CLOB数据的逻辑指针而不是数据本身。
在JAVA如何使用CLOB进行操作?
在绝大多数情况下,有2种方法使用CLOB。
1、相对比较小的,可以用String进行直接操作,把CLOB看成字符串类型即可。
2、如果比较大,可以用 getAsciiStream 或者 getUnicodeStream 以及对应的 setAsciiStream 和 setUnicodeStream 即可。
(1)读取数据:
ResultSet rs = stmt.executeQuery("SELECT TOP 1 * FROM Test1"); rs.next(); Reader reader = rs.getCharacterStream(2);
(2)插入数据:
PreparedStatement pstmt = con.prepareStatement("INSERT INTO test1 (c1_id, c2_vcmax) VALUES (?, ?)"); pstmt.setInt(1, 1); pstmt.setString(2, htmlStr); pstmt.executeUpdate();
(3)更新数据:
Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM test1"); rs.next(); Clob clob = rs.getClob(2); long pos = clob.position("dog", 1); clob.setString(1, "cat", len, 3); rs.updateClob(2, clob); rs.updateRow();
那么java是如何操作数据库clob字段的?
示例代码如下: package com.test.db.clob; import java.io.BufferedReader; import java.io.IOException; import java.io.Writer; import java.sql.Clob; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class ClobTest {undefined private static Connection conn; static {undefined try {undefined Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger"); } catch (ClassNotFoundException e) {undefined e.printStackTrace(); } catch (SQLException e) {undefined e.printStackTrace(); } } public static void main(String[] args) throws SQLException, IOException {undefined testInsert(); testUpdate(); testRead(); } private static void testInsert() throws SQLException {undefined String sql = "insert into test_clob values(1, empty_clob())"; Statement stm = conn.createStatement(); stm.execute(sql); } private static void testUpdate() throws SQLException, IOException {undefined String sql = "select content from test_clob where id = 1 for update"; Statement stm = conn.createStatement(); ResultSet rs = stm.executeQuery(sql); while (rs.next()) {undefined Clob c = rs.getClob(1); c.truncate(0);// clear Writer w = c.setCharacterStream(1);//The first position is 1 w.write("abc"); w.close(); c.setString(c.length() + 1, "abc"); conn点抗 mit(); } } private static void testRead() throws SQLException, IOException {undefined String sql = "select content from test_clob where id = 1"; PreparedStatement pstm = conn.prepareStatement(sql); ResultSet rs = pstm.executeQuery(); while (rs.next()) {undefined Clob clob = rs.getClob("content"); System.out.println("clob.getSubString(1, 2) -- " + clob.getSubString(1, 2)); System.out.println("clob.getSubString(1, (int)clob.length()) -- " + clob.getSubString(1, (int)clob.length())); BufferedReader r = new BufferedReader(clob.getCharacterStream()); String s; while ((s = r.readLine()) != null) {undefined System.out.println(s); } r.close(); } } }
求Java高手帮忙梳理一下这段Java代码吗不太能看的懂,最好能详细解释一下
这是一个表查找,查找表中与customer相等的数据。这个表有[customer,name,phone,....]等字段
.给出存储班级三十名学生基本信息的Java代码,基本信息的具体赋值由考生自拟?
下面是一个存储班级三十名学生基本信息的 Java 代码示例:
import java.util.ArrayList;
public class Student {
private String name;
private int age;
private String gender;
public Student(String name, int age, String gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getGender() {
return gender;
}
}
public class Classroom {
private ArrayListStudent students;
public Classroom() {
this.students = new ArrayListStudent();
}
public void addStudent(Student student) {
students.add(student);
}
public ArrayListStudent getStudents() {
return students;
}
}
public class Main {
public static void main(String[] args) {
Classroom classroom = new Classroom();
// 添加 30 名学生的基本信息
classroom.addStudent(new Student("Tom", 18, "Male"));
classroom.addStudent(new Student("Alice", 19, "Female"));
// ...
// 此处省略 28 名学生的信息
// 获取所有学生的信息
ArrayListStudent students = classroom.getStudents();
for (Student student : students) {
System.out.println("Name: " + student.getName());
System.out.println("Age: " + student.getAge());
System.out.println("Gender: " + student.getGender());
}
}
}
该代码定义了两个类:Student 类表示一个学生,包含了学生的姓名、年龄和性别等信息;Classroom 类表示一个班级,包含了一个学生的列表,并提供了添加学生和获取学生列表的方法。
在 Main 类的 main 方法中,我们首先实例化一个 Classroom 对象,然后依次添加 30 名学生的信息。最后,我们调用 getStudents 方法获取所
当前文章:javabio代码示例 java代码怎么写
标题路径:http://ybzwz.com/article/ddepsgj.html