Java调用存储过程的方法是通过调用Connection的实例方法prepareCall,prepareCall方法返回CallableStatement对象用于填充存储过程的参数。prepareCall方法形参是调用存储过程的sql语句,此参数的语法格式如下:
{call storedProcedureName(parameter-list)}其中,storedProcedureName是存储过程名称,parameter-list是存储过程参数列表。
例如,存储过程名为usp_test,有两个输入参数a,b。则调用代码看起来如下所示:
CallableStatement callableStatement = connection.prepareCall("{call usp_test(?,?)}")callableStatement.setObject("a","value-1")
callableStatement.setObject("b","value-2")
callableStatement.execute()
setLong 是将 sql中的?号 替换为相应的数字,setLong(9,1)是将第一个?号,替换为9其他的是查询结果、如果有结果、读取各种列,比如getString(2)就是读取第二列
要用输入流。import java.io.*
void readTxt(String txtpath){
File file = new File(txtPath)// 根据tx立文件路径,建了文件 D:\JAVA\OK.TXT
FileReader fr = null
bufferedReader br = null
String str = null
try{
fr = new FileReader(file)//文件输入流
br = new BufferedReader(fr)// 缓冲输入流
while((str = br.readLine())!=null){ //按行读取txt文件,存在str中
// 可以再这里对str进行操作
}
}catch(IOException e){
System.out.println(e.getMessage())}
try{
fr.close()
br.close()
}catch(IOException e){
System.out.println(e.getMessage())}
}