Click here to Skip to main content
15,665,166 members
Home / Discussions / Java
   

Java

 
AnswerRe: Observer Pattern - Restart Thread Again When Exception Occurs Pin
Richard MacCutchan5-Jul-17 21:55
mveRichard MacCutchan5-Jul-17 21:55 
QuestionNo value specified for parameter 2 Pin
karengsh3-Jul-17 5:27
karengsh3-Jul-17 5:27 
AnswerRe: No value specified for parameter 2 Pin
Richard Deeming3-Jul-17 5:29
mveRichard Deeming3-Jul-17 5:29 
GeneralRe: No value specified for parameter 2 Pin
karengsh3-Jul-17 5:33
karengsh3-Jul-17 5:33 
GeneralRe: No value specified for parameter 2 Pin
Richard Deeming3-Jul-17 7:06
mveRichard Deeming3-Jul-17 7:06 
GeneralRe: No value specified for parameter 2 Pin
karengsh3-Jul-17 16:33
karengsh3-Jul-17 16:33 
GeneralRe: No value specified for parameter 2 Pin
Richard MacCutchan3-Jul-17 21:20
mveRichard MacCutchan3-Jul-17 21:20 
GeneralRe: No value specified for parameter 2 Pin
karengsh4-Jul-17 5:51
karengsh4-Jul-17 5:51 
GeneralRe: No value specified for parameter 2 Pin
LynxEffect9-Aug-17 9:56
LynxEffect9-Aug-17 9:56 
Questionusing firefox progmatically with java Pin
Member 132904603-Jul-17 2:45
Member 132904603-Jul-17 2:45 
AnswerRe: using firefox progmatically with java Pin
Richard MacCutchan3-Jul-17 3:22
mveRichard MacCutchan3-Jul-17 3:22 
Questionjava.net.SocketException: Software caused connection abort: socket write error Pin
Django_Untaken1-Jul-17 9:57
Django_Untaken1-Jul-17 9:57 
GeneralRe: java.net.SocketException: Software caused connection abort: socket write error Pin
Richard MacCutchan1-Jul-17 20:53
mveRichard MacCutchan1-Jul-17 20:53 
GeneralRe: java.net.SocketException: Software caused connection abort: socket write error Pin
Django_Untaken1-Jul-17 23:39
Django_Untaken1-Jul-17 23:39 
GeneralRe: java.net.SocketException: Software caused connection abort: socket write error Pin
Richard MacCutchan2-Jul-17 1:37
mveRichard MacCutchan2-Jul-17 1:37 
GeneralRe: java.net.SocketException: Software caused connection abort: socket write error Pin
Django_Untaken2-Jul-17 7:33
Django_Untaken2-Jul-17 7:33 
GeneralRe: java.net.SocketException: Software caused connection abort: socket write error Pin
Richard MacCutchan3-Jul-17 3:23
mveRichard MacCutchan3-Jul-17 3:23 
QuestionInput:12-4-78==OUTPUT:12041978 //Input:9-4-78==OUTPUT:09041978 Pin
Member 1327696824-Jun-17 7:52
Member 1327696824-Jun-17 7:52 
AnswerRe: Input:12-4-78==OUTPUT:12041978 //Input:9-4-78==OUTPUT:09041978 Pin
Michael_Davies24-Jun-17 8:42
Michael_Davies24-Jun-17 8:42 
SuggestionRe: Input:12-4-78==OUTPUT:12041978 //Input:9-4-78==OUTPUT:09041978 Pin
Richard Deeming26-Jun-17 0:46
mveRichard Deeming26-Jun-17 0:46 
AnswerRe: Input:12-4-78==OUTPUT:12041978 //Input:9-4-78==OUTPUT:09041978 Pin
jschell28-Jun-17 6:16
jschell28-Jun-17 6:16 
QuestionHow should I go about getting the generated key from one DAOImpl to another DAOImpl ? Pin
karengsh18-Jun-17 5:30
karengsh18-Jun-17 5:30 
Dear experts,

I understand now that I have to get Generated Key in order to obtain my auto-incremental Id from a table.

However, after getting the generated key and set it to the model. I am stuck as to how to give it to my third table.

Java
public void insertTutor(tutor m) throws MyDataException { // 
		openConnection();
		try {
			connection.setAutoCommit(false);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String qry = INSERT_QRY;	
		try (    		    		
				
	PreparedStatement ps = connection.prepareStatement(qry)) {	;				
		   
	        ps.setString(1, m.getName());
	        ps.setString(2,  m.getNRIC());
                 ps.executeUpdate();	
	        ResultSet tableKeys = ps.getGeneratedKeys();
	        tableKeys.next();
	        int tutor_id = tableKeys.getInt(1);
	        m.setTutor_id(tutor_id); // here, I set my tutor id to the generatedkey
	        System.out.println(tutor_id);
	        connection.commit();
			} catch (SQLException e) {
		e.printStackTrace();
		....
	}}}}


And I do the same for my 2nd table.

My third table I need to make use of the Ids from the first and 2nd table.

So, do I create an insert like this ?

String qry = "INSERT INTO project.tutor_subject" + "(tutor_id, sub_id) values"
				+ "(?,?)"; 


And how do I go about doing the third DAOImpl and the controller to get the Ids to go into the third table ?

I have read that JPA and using MyBatis is better for many to many table insertion.

Should I do it via JPA and MyBatis ?
AnswerRe: How should I go about getting the generated key from one DAOImpl to another DAOImpl ? Pin
Mike.F.Hewitt18-Jun-17 11:14
Mike.F.Hewitt18-Jun-17 11:14 
GeneralRe: How should I go about getting the generated key from one DAOImpl to another DAOImpl ? Pin
karengsh23-Jun-17 21:34
karengsh23-Jun-17 21:34 
QuestionJava Pin
Member 1326557218-Jun-17 1:38
Member 1326557218-Jun-17 1:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.