1 个或多个属性查询:
Query query=session.createQuery(”select customername,customerid from Customer”)
List l=query.list();
For(int i=0;i {
Obejct[] object=(Object[])l.get(i);
Object[0] object[1]
}
}
分组: “select count(*),productname from Product group by productname order by productname”
取值与属性一样
配置的查询,在*.hbm.xml中
from Product where productid=:productid
]]>
Query query=session.getNamedQuery(sql);
联接1
”from Customer as customer join fetch customer.buySet”:将多的放到buySet属性中,得出的结是Customer有一个,Buy有多个
联接2
“from Customer as customer join customer.buySet”:得出的对象,customer与buy是1对1
子查询:
”from Customer as customer where (select count(*) from customer.buySet)>1″
6. String s = new String("xyz");创建了几个String Object? [中]
两个对象,一个是“xyx”,一个是指向“xyx”的引用对象s。
7. String与StringBuffer有什么区别? [难]
从表面看来String类只用一个加号(+)便完成了字符串的拼接,而StringBuffer类却要调用一个append()方法,是否实现起来更简洁,更单纯呢?其实不然,让我们了解一下程序运行内部发生了哪些事情:
经编译后程序的bytecode(字节码)展示出了实质: 在用String类对象直接拼接时,JVM会创建一个临时的StringBuffer类对象,并调用其append()方法完成字符串的拼接,这是因为String类是不可变的,拼接操作不得不使用StringBuffer类(并且--JVM会将"You are nice."和"I love you so much."创建为两个新的String对象)。之后,再将这个临时StringBuffer对象转型为一个String,代价不菲!可见,在这一个简单的一次拼接过程中,我们让程序创建了四个对象:两个待拼接的String,一个临时StringBuffer,和最后将StringBuffer转型成为的String--它当然不是最初的str了,这个引用的名称没变,但它指向了新的String对象。
而如果直接使用StringBuffer类,程序将只产生两个对象:最初的StringBuffer和拼接时的String("I love you so much."),也不再需要创建临时的StringBuffer类对象而后还得将其转换回String对象。
short s1 = 1; s1 = s1 + 1;有什么错?
short s1 = 1; s1 = s1 + 1; (s1+1运算结果是int型,需要强制转换类型)
short s1 = 1; s1 += 1;有什么错?
short s1 = 1; s1 += 1;(可以正确编译)
//1b. 接收键盘的输入
BufferedReader stdin =
new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Enter a line:");
System.out.println(stdin.readLine());
//2. 从一个String对象中读取数据
StringReader in2 = new StringReader(s2);
int c;
while((c = in2.read()) != -1)
System.out.println((char)c);
in2.close();
//3. 从内存取出格式化输入
try{
DataInputStream in3 =
new DataInputStream(
new ByteArrayInputStream(s2.getBytes()));
while(true)
System.out.println((char)in3.readByte());
}
catch(EOFException e){
System.out.println("End of stream");
}
//4. 输出到文件
try{
BufferedReader in4 =
new BufferedReader(
new StringReader(s2));
PrintWriter out1 =
new PrintWriter(
new BufferedWriter(
new FileWriter("F:\\nepalon\\ TestIO.out")));
int lineCount = 1;
while((s = in4.readLine()) != null)
out1.println(lineCount++ + ":" + s);
out1.close();
in4.close();
}
atch(EOFException ex){
System.out.println("End of stream");
}
//5. 数据的存储和恢复
try{
DataOutputStream out2 =
new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream("F:\\nepalon\\ Data.txt")));
out2.writeDouble(3.1415926);
out2.writeChars("\nThas was pi:writeChars\n");
out2.writeBytes("Thas was pi:writeByte\n");
out2.close();
DataInputStream in5 =
new DataInputStream(
new BufferedInputStream(
new FileInputStream("F:\\nepalon\\ Data.txt")));
BufferedReader in5br =
new BufferedReader(
new InputStreamReader(in5));
System.out.println(in5.readDouble());
System.out.println(in5br.readLine());
System.out.println(in5br.readLine());
}
catch(EOFException e){
System.out.println("End of stream");
}
1 个或多个属性查询:
Query query=session.createQuery(”select customername,customerid from Customer”)
List l=query.list();
For(int i=0;i {
Obejct[] object=(Object[])l.get(i);
Object[0] object[1]
}
}
分组: “select count(*),productname from Product group by productname order by productname”
取值与属性一样
配置的查询,在*.hbm.xml中
from Product where productid=:productid
]]>
Query query=session.getNamedQuery(sql);
联接1
”from Customer as customer join fetch customer.buySet”:将多的放到buySet属性中,得出的结是Customer有一个,Buy有多个
联接2
“from Customer as customer join customer.buySet”:得出的对象,customer与buy是1对1
子查询:
”from Customer as customer where (select count(*) from customer.buySet)>1″
6. String s = new String("xyz");创建了几个String Object? [中]
两个对象,一个是“xyx”,一个是指向“xyx”的引用对象s。
7. String与StringBuffer有什么区别? [难]
从表面看来String类只用一个加号(+)便完成了字符串的拼接,而StringBuffer类却要调用一个append()方法,是否实现起来更简洁,更单纯呢?其实不然,让我们了解一下程序运行内部发生了哪些事情:
经编译后程序的bytecode(字节码)展示出了实质: 在用String类对象直接拼接时,JVM会创建一个临时的StringBuffer类对象,并调用其append()方法完成字符串的拼接,这是因为String类是不可变的,拼接操作不得不使用StringBuffer类(并且--JVM会将"You are nice."和"I love you so much."创建为两个新的String对象)。之后,再将这个临时StringBuffer对象转型为一个String,代价不菲!可见,在这一个简单的一次拼接过程中,我们让程序创建了四个对象:两个待拼接的String,一个临时StringBuffer,和最后将StringBuffer转型成为的String--它当然不是最初的str了,这个引用的名称没变,但它指向了新的String对象。
而如果直接使用StringBuffer类,程序将只产生两个对象:最初的StringBuffer和拼接时的String("I love you so much."),也不再需要创建临时的StringBuffer类对象而后还得将其转换回String对象。
short s1 = 1; s1 = s1 + 1;有什么错?
short s1 = 1; s1 = s1 + 1; (s1+1运算结果是int型,需要强制转换类型)
short s1 = 1; s1 += 1;有什么错?
short s1 = 1; s1 += 1;(可以正确编译)
//1b. 接收键盘的输入
BufferedReader stdin =
new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Enter a line:");
System.out.println(stdin.readLine());
//2. 从一个String对象中读取数据
StringReader in2 = new StringReader(s2);
int c;
while((c = in2.read()) != -1)
System.out.println((char)c);
in2.close();
//3. 从内存取出格式化输入
try{
DataInputStream in3 =
new DataInputStream(
new ByteArrayInputStream(s2.getBytes()));
while(true)
System.out.println((char)in3.readByte());
}
catch(EOFException e){
System.out.println("End of stream");
}
//4. 输出到文件
try{
BufferedReader in4 =
new BufferedReader(
new StringReader(s2));
PrintWriter out1 =
new PrintWriter(
new BufferedWriter(
new FileWriter("F:\\nepalon\\ TestIO.out")));
int lineCount = 1;
while((s = in4.readLine()) != null)
out1.println(lineCount++ + ":" + s);
out1.close();
in4.close();
}
atch(EOFException ex){
System.out.println("End of stream");
}
//5. 数据的存储和恢复
try{
DataOutputStream out2 =
new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream("F:\\nepalon\\ Data.txt")));
out2.writeDouble(3.1415926);
out2.writeChars("\nThas was pi:writeChars\n");
out2.writeBytes("Thas was pi:writeByte\n");
out2.close();
DataInputStream in5 =
new DataInputStream(
new BufferedInputStream(
new FileInputStream("F:\\nepalon\\ Data.txt")));
BufferedReader in5br =
new BufferedReader(
new InputStreamReader(in5));
System.out.println(in5.readDouble());
System.out.println(in5br.readLine());
System.out.println(in5br.readLine());
}
catch(EOFException e){
System.out.println("End of stream");
}