关于eclipse开发符值的问题
有下面一段代码:
package servers;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ser01 {
public String exec_procedure()
{
String JDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";//SQL数据库引擎
String connectDB="jdbc:sqlserver://localhost:1433;DatabaseName=V302N";//数据源
String user="sa";
String password="123";
return p_bs_select_customer(JDriver,connectDB,user,password);
}
public String returnprocedure(String user)
{
//return "Hello,"+user;
return exec_procedure();
}
public String p_bs_select_customer(String JDriver,String connectDB,String user,String password)
{
//return JDriver+" "+connectDB+" "+user+" "+password;
String JDriver2="com.microsoft.sqlserver.jdbc.SQLServerDriver";//SQL数据库引擎
try
{
Class.forName(JDriver2);//加载数据库引擎,返回给定字符串名的类
//System.out.println("调用成功");
}
catch(ClassNotFoundException e)
{
return e.getMessage();
//return JDriver+" "+connectDB+" "+user+" "+password;
//return "加载数据库引擎失败";
}
//创建数据库连接对象
String input="";
Connection con;
try
{
//System.out.println(connectDB+" "+user+" "+password);
con = DriverManager.getConnection(connectDB,user,password);
//创建存储过程
//CallableStatement cstmt = con.prepareCall("{call p_wh_productout_load}");
Statement cstmt= con.createStatement();//创建SQL命令对象
//ResultSet cstmt= stmt.executeQuery("exec p_wh_productout_load");
{
//调用存储过程并返回数据集
ResultSet rs2= cstmt.executeQuery("SET NOCOUNT ON exec p_bs_select_customer @type=2");
while(rs2.next())
{
//JSONObject input = new JSONObject();
//System.out.println(rs2.getString("personnel"));
//获取返回值结果
input=input+rs2.getString("code")+","+rs2.getString("name")+","+rs2.getString("type")+"\n";
}
}
cstmt.close();
con.close();//关闭数据库连接
//System.out.println(jsonArray.toString());
}
catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
return "数据库连接错误";
}//连接数据库对象
return input;
}
}
ResultSet rs2= cstmt.executeQuery("SET NOCOUNT ON exec p_bs_select_customer @type=2");
String s = "SET NOCOUNT ON exec p_bs_select_customer @type=" + x;// x 是你的需要赋值的值
ResultSet rs2= cstmt.executeQuery(s);