如何取到输出参数 @Identity @Pointer 的值?

tenny 2003-12-30 01:03:22
// sample:
// 问题如下:
// 如何取到输出参数 @Identity @Pointer 的值?
// 为什么 stmt.getResultSet()为NULL?
// 有什么方法可以将SqlString 的SQL语句单条的取出来?

import java.sql.*;
import java.*;
public class sqlparamt {

public static void main(String[] args) {
String driverName = "com.jnetdirect.jsql.JSQLDriver"; String sourceURL = "jdbc:JSQLConnect://localhost:1433";
// Load the driver.
try {
// Load the driver class
Class.forName(driverName);
String user = "sa" ;
String password = "";
// Create the connection through the DriverManager
Connection con = DriverManager.getConnection(sourceURL, user, password);
// Define the data source for the driver
String database = "Northwind";
con.setCatalog(database);

/*SqlString = "INSERT INTO Employees (LastName, FirstName, Title, HireDate, ReportsTo, Photo) " +
"Values(@LastName, @FirstName, @Title, @HireDate, @ReportsTo, 0x0);" +
"SELECT @Identity = SCOPE_IDENTITY();" +
"SELECT @Pointer = TEXTPTR(Photo) FROM Employees WHERE EmployeeID = @Identity" */

String sqlcommand = "INSERT INTO Employees (LastName, FirstName, Title, HireDate, ReportsTo, Photo) " + "Values(?,?,?,?,?,?);" +"SELECT ? = SCOPE_IDENTITY();" + "SELECT ? = TEXTPTR(Photo) FROM Employees WHERE EmployeeID = ?";

PreparedStatement stmt = con.prepareStatement(sqlcommand);
stmt.setString(1, "te12321312321") ;
stmt.setString(2,"ddddd");
stmt.setString(3,"12");
stmt.setTimestamp(4, new Timestamp(2003,12,16,12,12,12,12));
stmt.setInt(5,1);
String by = "11";
byte[] bb = by.getBytes();
stmt.setBytes(6,bb);
stmt.setInt(7,0);
stmt.setObject(8,bb);
stmt.setInt(9,0);

stmt.execute();

//stmt.executeQuery();
System.out.println("..more reuslt set is.."+stmt.getResultSet());
System.out.println("..more reuslt set is.." + stmt.getMoreResults() );

System.out.println("..more reuslt set is.." + stmt.getMoreResults() );

stmt.close();
con.close();

}
catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
catch (SQLException sqle){
sqle.printStackTrace();
}

}

}
...全文
9 点赞 收藏 回复
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复

还没有回复,快来抢沙发~

发帖
Java EE
创建于2007-09-28

6.6w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
申请成为版主
帖子事件
创建了帖子
2003-12-30 01:03
社区公告
暂无公告