com.microsoft.sqlserver.jdbc.SQLServerException:'{

时间:2017-03-13 11:43:11

标签: procedure

我是java新手。当我们尝试使用下面的代码时,我们的一个存储过程中使用了一些tabled值参数,然后我们得到了以下错误。

  

com.microsoft.sqlserver.jdbc.SQLServerException:附近的语法不正确   '{'。

     

import java.sql。*;

     

import com.microsoft.sqlserver.jdbc.SQLServerDataTable;进口   com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement;

     

public class DB_SP_Call {          连接conn = null;        语句stmt = null;        String dbserver =“10.42。:1198”;        String db =“t1c”;        String USER =“t1c”;        String PWD =“t1c”;        String sql; static final String JDBC_DRIVER =“com.microsoft.sqlserver.jdbc.SQLServerDriver”;公共无效   runSP(){             String DB_URL =“jdbc:sqlserver://”+ dbserver +“; databaseName =”+ db;尝试{                     的Class.forName(JDBC_DRIVER);

                  //STEP 3: Open a connection
              System.out.println("Connecting to database...");
              conn = DriverManager.getConnection(DB_URL,USER,PWD);
              System.out.println("Creating statement...");
              stmt = conn.createStatement();
              //SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement)conn.prepareStatement("{call exec
     

t1c.scnTargetingBYO   @InstrID =?@ CAS =?@页次=?@每页=?@ =的SortField?,@ TotalRecNum =?   输出,@ OutputFirmFund =?@下载=?@ FirmContactData =?@ FirmList =?@ CustTagList =?@ LocationList =?@方向=?@ InvTypeIDList =?@ InvStyleIDList =?,@ AdvisoryList = ?,@ SocialyResposible =?,@ TurnoverList =?,@ SecurityActivity =?,@ InstWithUpside =?,@ MarketCapPass =?,@ PNI =?,@ EventFirmMet =?,@的EventType =?,@ CorpParticipant =?,@ SectorList = ?,@ GeoIDList =?,@ MarketCapStr =?,@ HoldType =?,@ ActThreshold =?,@ SavedDataFlag =?   输出,@ DisplayGroupFlag =,@ PerPeerFlag =,@用户ID =,@的AccountID =}“);????

              SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement)conn.prepareStatement("{ call exec
     

t1c.scnTargetingBYO   ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?   }“);                     pstmt.setInt(1,264998);                     pstmt.setString(2,“P”);                     pstmt.setInt(3,0);                     pstmt.setInt(4,100);                     pstmt.setString(5,“Pos DESC”);                     pstmt.setInt(6,2308);                     pstmt.setInt(7,0);                     pstmt.setInt(8,0);                     pstmt.setInt(9,0);

              SQLServerDataTable p10 = new SQLServerDataTable(); 
              p10.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
              p10.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
              pstmt.setStructured(10, "t1c.InvIDTabType", p10);

              SQLServerDataTable p11 = new SQLServerDataTable(); 
              p11.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
              p11.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
              pstmt.setStructured(11, "t1c.InvIDTabType", p11);

              SQLServerDataTable p12 = new SQLServerDataTable(); 
              p12.addColumnMetadata("LocationID",java.sql.Types.NUMERIC);
              p12.addColumnMetadata("LocationTypeID",java.sql.Types.NUMERIC);
              Object[] row= new Object[2];
              row[0]=new Integer(10006);
              row[1]=new Integer(5);
              p12.addRow(row);
              pstmt.setStructured(12, "t1c.LocationList", p12);

              pstmt.setInt(13,1);

              SQLServerDataTable p14 = new SQLServerDataTable();
              p14.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
              p14.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
              p14.addColumnMetadata("Lev",java.sql.Types.NUMERIC);
              Object[] row1= new Object[3];
              row1[0]=new Integer(200);
              row1[1]=null;
              row1[2]=new Integer(2);
              p14.addRow(row1);
              Object[] row2= new Object[3];
              row2[0]=new Integer(600);
              row2[1]=null;
              row2[2]=new Integer(1);
              p14.addRow(row2);
              Object[] row3= new Object[3];
              row3[0]=new Integer(100);
              row3[1]=null;
              row3[2]=new Integer(2);
              p14.addRow(row3);
              Object[] row4= new Object[3];
              row4[0]=new Integer(500);
              row4[1]=null;
              row4[2]=new Integer(1);
              p14.addRow(row4);
              Object[] row5= new Object[3];
              row5[0]=new Integer(300);
              row5[1]=null;
              row5[2]=new Integer(2);
              p14.addRow(row5);
              pstmt.setStructured(14, "t1c.InvIDTabType2", p14);

              SQLServerDataTable p15 = new SQLServerDataTable();
              p15.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
              p15.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
              p15.addColumnMetadata("Lev",java.sql.Types.NUMERIC);
              pstmt.setStructured(15, "t1c.InvIDTabType2", p15);

              pstmt.setInt(16,0);
              pstmt.setString(17,"NULL");



              SQLServerDataTable p18 = new SQLServerDataTable();
              p18.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
              p18.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
              pstmt.setStructured(18, "t1c.InvIDTabType", p18);

              pstmt.setInt(19,0);
              pstmt.setInt(20,0);
              pstmt.setInt(21,0);
              pstmt.setInt(22,0);
              pstmt.setInt(23,3);

              SQLServerDataTable p24 = new SQLServerDataTable();
              p24.addColumnMetadata("EventID",java.sql.Types.NUMERIC);
              p24.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
              p24.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
              pstmt.setStructured(24, "cms.EvtLinkTabType", p24);


              SQLServerDataTable p25 = new SQLServerDataTable();
              p25.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
              p25.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
              pstmt.setStructured(25, "t1c.InvIDTabType", p25);


              SQLServerDataTable p26 = new SQLServerDataTable();
              p26.addColumnMetadata("Type",java.sql.Types.VARCHAR);
              p26.addColumnMetadata("ID",java.sql.Types.NUMERIC);
              p26.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
              p26.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
              p26.addColumnMetadata("ID3",java.sql.Types.NUMERIC);
              p26.addColumnMetadata("ID4",java.sql.Types.NUMERIC);
              p26.addColumnMetadata("ID5",java.sql.Types.NUMERIC);
              p26.addColumnMetadata("ID6",java.sql.Types.NUMERIC);
              p26.addColumnMetadata("ID7",java.sql.Types.NUMERIC);
              pstmt.setStructured(26, "t1c.InvSpecialIDTabType2", p26);


              SQLServerDataTable p27 = new SQLServerDataTable();
              p27.addColumnMetadata("Type",java.sql.Types.VARCHAR);
              p27.addColumnMetadata("ID",java.sql.Types.NUMERIC);
              p27.addColumnMetadata("ID1",java.sql.Types.NUMERIC);
              p27.addColumnMetadata("ID2",java.sql.Types.NUMERIC);
              p27.addColumnMetadata("ID3",java.sql.Types.NUMERIC);
              p27.addColumnMetadata("ID4",java.sql.Types.NUMERIC);
              p27.addColumnMetadata("ID5",java.sql.Types.NUMERIC);
              p27.addColumnMetadata("ID6",java.sql.Types.NUMERIC);
              p27.addColumnMetadata("ID7",java.sql.Types.NUMERIC);
              pstmt.setStructured(27, "t1c.InvSpecialIDTabType2", p27);

              pstmt.setString(28,"NULL");
              pstmt.setInt(29,1);

              SQLServerDataTable p30 = new SQLServerDataTable();
              p30.addColumnMetadata("Category", java.sql.Types.VARCHAR);
              p30.addColumnMetadata("ActType", java.sql.Types.NUMERIC);
              p30.addColumnMetadata("Threshold", java.sql.Types.VARCHAR);
              p30.addColumnMetadata("Min", java.sql.Types.NUMERIC);
              p30.addColumnMetadata("Max", java.sql.Types.NUMERIC);

              Object[] row6= new Object[5];
              row6[0]=new String("O");
              row6[1]=new Integer(0);
              row6[2]=new String("S");
              row6[3]=new Integer(1);
              row6[4]=null;
              p30.addRow(row6);
              Object[] row7= new Object[5];
              row7[0]=new String("F");
              row7[1]=null;
              row7[2]=new String("E");
              row7[3]=new Integer(5);
              row7[4]=null;
              p30.addRow(row7);
              pstmt.setStructured(30, "t1c.InvActThresholdTabType", p30);

              pstmt.setInt(31,2);
              pstmt.setInt(32,2946);
              pstmt.setInt(33,0);
              pstmt.setInt(34,234568);
              pstmt.setInt(35,21022);


              ResultSet rs = pstmt.executeQuery();
              //ResultSet rs = pstmt.execute();
                ResultSetMetaData metaData = rs.getMetaData();
                //System.out.println("Hi, fetching resultset.........");
                System.out.println(metaData.getColumnCount());

                while(rs.next()){


                   int intdata  = rs.getInt("LgcyInvestorID");
                   System.out.println(intdata);
                }

      }catch(Exception e){            e.printStackTrace();

          }finally{
        //finally block used to close resources
        try{
                     if(stmt!=null)
                     stmt.close();
               }

        catch(SQLException se2)
        {
        }// nothing we can do
        try{
              if(conn!=null)
              conn.close();
        }catch(SQLException se){
          se.printStackTrace();
        }//end finally try

   }
                          }
     

public static void main(String [] args){                 DB_SP_Call dbcall = new DB_SP_Call();                 dbcall.runSP(); }

     

}

请专家在这方面取得帮助。

0 个答案:

没有答案