2009-11-11 5 views
1

값을 SQL Server에 삽입하고 싶지만 문제가 있습니다. 매개 변수에 값을 모두 전달하면 하나의 값을 선택하면 삽입되지 않습니다. 그러면 데이터베이스 이름이 삽입됩니다. 예제 및 테이블은 항목값을 SQL 서버에 삽입

입니다.

완벽한 삽입 문 또는 아닙니다?

try 
{ 
    int val = stmt.executeUpdate("INSERT item (patientid,itemid) VALUES(nPatientID," + LrBn.TestID+ ")"); 
    out.println("1 row affected"); 
} 
catch (SQLException s) 
{ 
    System.out.println("SQL statement is not executed!"); 
} 

<% 
if(testname!=null) 
    { 
      LrBn.beginInsert(); 
     for(int i=0; i<testname.length; i++) 
      { 
        nCount++ ; 
       LrBn.ResultID=0; 
       try 
        { 
       LrBn.TestID = Integer.parseInt(testname[i]) ; 
      } catch(NumberFormatException ex) 
      { 
       LrBn.TestID = 0 ; 
      } 

         LrBn.GroupID = nGroupID ; 
         LaBn.locateRecord(LrBn.TestID) ; 

         short nemergencyType = com.hims.emergencyType.normal ; 
         try 
         { 
        nemergencyType = Short.parseShort(request.getParameter("emergencyType")); 
        } 
         catch(NumberFormatException ex) 
         { 
         nemergencyType = com.hims.emergencyType.normal ; 
         }  
      LrBn.Emergency = nemergencyType; 
        LrBn.ResultType = LaBn.TestResultType ; 
         LrBn.PatientID = nPatientID ; 
         LrBn.DoctorID = LogUsr.DoctorID; 
        LrBn.UnitID = LogUsr.UnitID ; 
         LrBn.RequestTime = com.webapp.utils.DateHelper.requestDateTime(request, "RequestTime"); 
       LrBn.CollectionTime = null; 
      LrBn.ResultTime = null; 
         LrBn.CollectedBy = 0 ; 
      LrBn.TestDoneBy = 0 ; 
      LrBn.PathologyUnitID = 0 ; 
         LrBn.BoolValue = 0; 
         LrBn.ScalarValue = null ; 
         LrBn.DescValue = null ; 
         LrBn.TestStatus = com.hims.TestStatusType.REQUESTED ; 
         LrBn.TestCharges = LaBn.TestCharge ; 
      LrBn.PaymentStatus = com.hims.PaymentStatus.PENDING ;      
         LrBn.continueInsert(); 

         Class.forName("net.sourceforge.jtds.jdbc.Driver"); 
        Connection conn = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/sample", "sa", "sa1234"); 
         java.sql.Statement stmt = conn.createStatement(); 
         try 
         { 
         int val = stmt.executeUpdate("INSERT item (patientid,itemid) VALUES(nPatientID," + LrBn.TestID+ ")"); 
         out.println("1 row affected"); 
       } 
       catch (SQLException s) 
         { 
          System.out.println("SQL statement is not executed!"); 
       } 
         stmt.close(); 
         conn.close(); 

     } // end for 
       LrBn.endInsert(); 
    } 
%> 

답변

0

코드의 첫 번째 줄에서 상대 : 당신이 SQL 예외 및 patientid을 받고있는 경우

int val = stmt.executeUpdate("INSERT item (patientid,itemid) VALUES(nPatientID," 
     + LrBn.TestID+ ")");  

하면 것을 해결할 수 IDENTITY 필드의 일종 대신 stmt.executeUpdate("INSERT item (itemid) VALUES(" + LrBn.TestID + ")"); 을 수행하여.

문제가되지 않는다면 사과드립니다. 질문을 명확히해야 할 수도 있습니다.

관련 문제