2023-09-12 16:59来源:m.sf1369.com作者:宇宇
1、getString:String getString(int columnIndex),throws SQLException以Java编程语言中 String 的形式获取此 ResultSet 对象的当前行中指定列的值。
2、1代表第一列。
例如:
columnIndex - 第一个列是1,第二个列是2,……
返回:
列值;如果值为SQL NULL,则返回值为null
抛出:
SQLException
扩展资料:
ResultSet 对象的用法:
ResultSet 对象具有指向其当前数据行的指针。最初,指针被置于第一行之前。next 方法将指针移动到下一行;因为该方法在 ResultSet 对象中没有下一行时返回 false,所以可以在 while 循环中使用它来迭代结果集。
JAVA中去掉空格1. String.trim()trim()是去掉首尾空格2.str.replace(" ", ""); 去掉所有空格,包括首尾、中间复制代码 代码如下:String str = " hell o "
;String str2 = str.replaceAll(" ", "")
;System.out.println(str2)
;3.或者replaceAll(" +",""); 去掉所有空格4.str = .replaceAll("\\s*", "");可以替换大部分空白字符, 不限于空格\s 可以匹配空格、制表符、换页符等空白字符的其中任意一个 您可能感兴趣的文章:java去除字符串中的空格、回车、换行符、制表符的小例子
前台页面?是b/s程序?
如果是b/s程序那打印就是在服务端接的打印机里打印出来,这个时候最好是不要有预览,否则服务程序就挂起来了不会继续执行。
如果是在前台打印那使用js来操作。你点击按钮后,后台读取excel文件并用一个页面显示出预览效果,再用js自动调用页面的打印就可以在前台电脑带的打印机打印出来了。
LinkedList llist=new LinkedList();llist.add("..");...String[] str=new String[llist.size()];llist.toArray(str);这样Object[]数组就转到了String[]数组了,你可以去参考toArray()方法原型:public synchronized <T> T[] toArray(T[] a) { if (a.length < elementCount) a = (T[]
)java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), elementCount); System.arraycopy(elementData, 0, a, 0, elementCount); if (a.length > elementCount) a[elementCount] = null; return a; }
// 定义注解并指定java注解保留策略为运行时RUNTIME,运行时注入到JAVA字节码文件里// 这样才可以在运行时反射并获取它。@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)@interface MyAnnotation{ String key() default ""; int value() default 0; }// 使用注解@MyAnnotation(key="key1",value=200)class MyClass{}// 反射注解public static void main(String[] args){ MyClass myClass=new MyClass(); MyAnnotation annotation=myClass.getClass().getAnnotation(MyAnnotation.class)
; System.out.println("key="+annotation.key()+"\tvalue="+annotation.value());}
public class ReadText { public static void main(String[] args) { String line = ""; try { BufferedReader br = new BufferedReader(new FileReader("D:\\test.txt")); while((line = br.readLine()) != null){ br.skip(line.length());//在此次加入你要跳过行的条件 System.out.println(line); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }}test.txt的内容是12345执行结果是135
楼主,如果写,先判断要写多大的文件、然后分段写,各线程写自己的段如果读,也是先得到文件大小、再分段,然后各线程读自己的段
Java读取文件的方法
代码如下:
import java.io.*;
public class ReadFileDemo {
public static void main(String[] args) {
//读取c盘的file1文件
File file = new File("C://file1.txt");
BufferedInputStream bis = null;
FileInputStream fis= null;
try
{
//第一步 通过文件路径来创建文件实例
fis = new FileInputStream(file);
/*把FileInputStream实例 传递到 BufferedInputStream
目的是能快速读取文件
*/
bis = new BufferedInputStream(fis);
/*available检查是不是读到了文件末尾 */
while( bis.available() > 0 ){
System.out.print((char)bis.read());
}
}catch(FileNotFoundException fnfe)
{
System.out.println("文件不存在" + fnfe);
}
catch(IOException ioe)
{
System.out.println("I/O 错误: " + ioe);
}
finally
{
try{
if(bis != null && fis!=null)
{
fis.close();
bis.close();
}
}catch(IOException ioe)
{
System.out.println("关闭InputStream句柄错误: " + ioe);
}
}
}
}
String类中有一个方法 public boolean contains(Sting s)就是用来判断当前字符串是否含有参数指定的字符串 例 s1=“takecatb” s2=“te” 语句:s1.contains(s2) //s1调用这个方法 若其值为ture说明s1包含s2 若为fasle 则不包含
换行符"\n"(向右斜线)是正确的。在C语言、C++、java、C#、Lua等众多编程语言中,"\n"都表示一个换行符。其中,符号“\”是一个转义符。
它向编译器说:“注意啦嘿!我后面那一个字符不要直接输出,让后面的那个字符来决定让一个特殊字符(即程序员不方便在源代码中直接表示的字符)替代我的位置!”
编译过程中,编译器发现:“\”后面跟了一个“n”。则它就会把整个“\n”替换成一个换行符。而"/"就没有任何比较特殊的意义了。它在字符串外,是一个除法运算符;在字符串里,仅仅是一个“/”字符而已罢了。至于那些在C语言、C++、Java里写“/n”来试图换行的人民。。。我想他们有必要重温一下HelloWord。。。。