|
JSONObject ret = new JSONObject();
String DBDriver = "net.sourceforge.jtds.jdbc.Driver";
String ConnStr = "jdbc:jtds:sqlserver://127.0.0.1:1433;DatabaseName=FreeErp";
Connection conn;
try {
Class.forName(DBDriver).newInstance();
conn = DriverManager.getConnection(ConnStr, "sa", "******");
// 创建一个 CallableStatement对象来调用数据库存储过程
CallableStatement stat = conn.prepareCall("{call sp_GetMyTask(?,?,?,?)}"); //[sp_GetTaskNum]
// 设置IN参数,参数以顺序匹配
stat.setString(1, "system");
stat.setString(2, "%");
stat.setString(3, "%");
stat.setString(4, "1=1");
// 执行存储过程
stat.execute();
// 获取返回的数据集
ResultSet rs = stat.getResultSet();
System.out.println("rs:" + rs);
while (rs != null && rs.next()) {
i++;
System.out.println(rs.getRow()+" seqno: " + rs.getString(1));
//System.out.println(new StringBuilder("FLOWTYPE:").append(rs.getString(1)).append("\t NOTE:").append(rs.getInt(2)).append("\t PROCNAME:").append(rs.getString(3))
// .append("\t INITIATOR:").append(rs.getString(4)).toString());
}
Table table=Transform.resultSetToTable(rs, "", null);
ret=Transform.tableToJson(table);
System.out.println("ret哦:" + ret.toJSONString());
} catch (Exception e) {
e.printStackTrace();
} |
|