Jump to content

[Microsoft][SQL Native Client][SQL Server]Violation of PRIMARY KEY constraint 'P


AMB
 Share

Recommended Posts

Bom dia estou com dificuldade em executar um pedaço de código e não consigo perceber, a conexão está correcta. Estou a utilizar o eclipse e o microsoft sql server manegement studio.

o erro ocorre no seguinte:

String SQL4 = "SELECT SERIES_REF FROM dosr_series WHERE STUDY_REF = '"+st2+"'";
			                    Statement stm4 = cn.createStatement();
			                    ResultSet rss4 = stm4.executeQuery(SQL4);
			                    System.out.println("SELECT SERIES_REF FROM dosr_series WHERE STUDY_REF = '"+st2+"'");
			                    while (rss4.next ()){
			                    	String st4 = rss4.getString("SERIES_REF");
			                    	System.out.println(st4);
			                    	
			                    	String SQL5 = "SELECT EXPOSURE FROM dosr_object WHERE SERIES_REF = '"+st4+"'";
			                    	Statement stm5 = cn.createStatement();
			                    	ResultSet rss5 = stm5.executeQuery(SQL5);
			                    	System.out.println("SELECT EXPOSURE FROM dosr_object WHERE SERIES_REF = '"+st4+"'");
			                    	while (rss5.next()){
			                    		String st5 = rss5.getString("EXPOSURE");
			                    		System.out.println(st5);
			                    	
			                    	
			                    
						//inserção dos dados na BD quando exame é CT
							stsql.executeUpdate("INSERT INTO Patient (Pat_Id, Study_Id, Name, DateOfBirth, Sex, Age, Type) VALUES ('"+id+"','"+nr+"','"+nome+"','"+fimdn+"','"+sexo+"','"+idd+"','"+ty+"')");
							stsql.executeUpdate("INSERT INTO Exam (Pat_Id, mas, nh) VALUES ('"+id+"','"+st5+"','"+nxh+"')");

Ou seja eu quero guardar dois valores st5 para o o mesmo paciente e não consigo

Qual é o problema???

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.