This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Employee service Course Service | |
| @Autowired @Autowired | |
| CourseService courseService; @Transactional(propagation=Propagation.REQUIRES_NEW) | |
| @Autowired public void saveCourse() | |
| EmplyeeRepository empRepo; { | |
| @Transactional int a = 4; | |
| public void saveEmplyee() a =a/0; /// devide by zer exception | |
| } | |
| { | |
| Empylye emp = new Empylye(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| table student | |
| bookid authorid | |
| 1 1 | |
| 1 2 | |
| 2 2 | |
| select s.bookid from student s | |
| group by s.bookid | |
| having count(s.authorid) =1 | |
| Explaination :::: As we know that "group by" is executed before "having" so first line number 8 will be executed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| book table | author table | BOOK_AUTHORS | |
| id name | id name | book_id author_id | |
| 1 dubai visit | 1 abc | 1 1 | |
| 2 pak visit | 2 def | 1 2 | |
| | 2 2 | |
| SELECT ba.book_Id FROM BOOK_AUTHORS ba | |
| JOIN Book b ON ba.book_Id = b.id | |
| JOIN BOOK_AUTHORS ba2 ON b.id = ba2.book_Id | |
| WHERE ba2.authors_Id = 2 | |
| GROUP BY ba.book_Id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Interface BatchPreparedStatementSetter | |
| int getBatchSize() | |
| void setValues(PreparedStatement ps, int i) | |
| return this.jdbcTemplate.batchUpdate( | |
| "update books set firstName = ? where id = ?", | |
| new BatchPreparedStatementSetter() { | |
| public void setValues(PreparedStatement ps, int i) | |
| throws SQLException { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| System.out.print("Write once, run everywhere!"); | |
| System.out.println(""); | |
| System.out.println("Write"); | |
| System.out.println("once,"); | |
| System.out.println("run"); | |
| System.out.println("everywhere!"); | |
| System.out.println("*******************************"); | |
| System.out.println("* Write once, run everywhere! *"); | |
| System.out.println("* *"); | |
| System.out.print("*******************************"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| System.out.print("Write once, run everywhere!"); | |
| String[] array = {"Write","once,","run","everywhere!"}; | |
| for(int k = 0; k<=array.length-1; k++) | |
| { | |
| if(k==0) | |
| { | |
| System.out.println(); | |
| for(int k3 = 0; k3<=array.length-1; k3++) | |
| { | |
| System.out.println(array[k3]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| User post userfriend | |
| uid(pk) pid userid(fk) title frid(pk) userid(fk) friendid(fk) | |
| 1 1 1 p1 1 1 2 | |
| 2 2 1 p2 2 1 3 | |
| 3 3 2 p3 3 2 3 | |
| 4 4 3 p4 4 3 4 | |
| 5 5 4 p5 5 4 5 | |
| eexpected out put title | |
| p1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version 1 version 2 version 3 | |
| @Entity public class UserPost public class UserInstitute | |
| public class User { { | |
| { String name; String name; | |
| String name; List<Post> post ; List<Insitiute> insitute; | |
| List<Post> post ; } } | |
| List<Insitiute> insitute; | |
| } | |
| "select from User u fetch join u.post where id = 1" | |
| it will result in inner join query so correct but |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| User(table) Post(table) Comments(table) | |
| userid name postid title commntsid commnets userid postid | |
| @Entity @Entity @Entity | |
| @Table(name = "user") @Table(name = "post") @Table(name = "comments") | |
| public class User public class Post public class Comments | |
| { { { | |
| @OneToMany(mappedBy = "user") | |
| List<Post> post=new ArrayList<>(); @ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY) | |
| @JoinColumn(name = "uid") @JoinColumn(name = "uid") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| user friends | |
| userid name uid friendid | |
| 1 abc 1 2 | |
| 2 def 1 3 | |
| 3 xyz 2 3 | |
| 4 ghf 3 4 | |
| where as uid and friendid in friends table are composite primary key and they are forign key from userid of user tabale . | |
| question 1) when i have to insert into friends table than i will insert like "insert into friends(udi , friendid) values(1,2)" . | |
| am i correct? |
NewerOlder