i'm populating my tableview from mysql database but only the column ID is the only one that's populated.
my main:
public void populate() throws Exception{
ObservableList<userdata1> data = FXCollections.observableArrayList();
tableView();
try{
String query = "select * from members";
ps = new Connect().connectDatabase1();
rs = ps.executeQuery(query);
while(rs.next()){
data.add(new userdata1(rs.getInt(1),rs.getString(2),rs.getInt(3)));
tblView.setItems(data);
}
}catch(Exception e){
System.out.print("asdqweasd");
}
}
public void tableView()throws Exception{
tblView.getItems().clear();
tblView.getColumns().clear();
rs = ps.executeQuery("SELECT * FROM members");
ObservableList<userdata1> data = FXCollections.observableArrayList();
TableColumn column1 = new TableColumn("ID");
column1.setMinWidth(85);
column1.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<>("ID"));
TableColumn column2 = new TableColumn("Name");
column2.setMinWidth(565);
column2.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<>("comp_name"));
TableColumn column3 = new TableColumn("STATUS");
column3.setMinWidth(123);
column3.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<>("mem_status"));
tblView.getColumns().addAll(column1,column2,column3);
}
my userdata1:
public class userdata1 {
public SimpleIntegerProperty ID;
public SimpleStringProperty comp_name;
public SimpleIntegerProperty mem_status;
public userdata1(Integer id, String comp_name, Integer mem_status){
this.ID = new SimpleIntegerProperty(id);
this.comp_name = new SimpleStringProperty(comp_name);
this.mem_status = new SimpleIntegerProperty(mem_status);
}
public Integer getID() {
return ID.get();
}
public String getcomp_name(){
return comp_name.get();
}
public Integer getmem_status() {
return mem_status.get();
}
public void setID(Integer id) {
this.ID.set(id);
}
public void setcomp_name(String comp_name ) {
this.comp_name.set(comp_name);
}
public void setmem_status(Integer mem_status) {
this.mem_status.set(mem_status);
}
}
the data mem_status and comp_name is not populating their respective columns
As UserData1 already contains Properties, you can set the according Property to the cellValueFactory:
public class UserData1 {
private StringProperty comp_name;
//additional fields, getters and setters
public StringProperty comp_nameProperty() {
return comp_name;
}
}
setCellValueFactory(cellData -> cellData.getValue().comp_nameProperty());
If you want to stick to the PropertyValueFactory you have to access the fields according to the CamelCase convention:
column2.setCellValueFactory(new PropertyValueFactory<>("comp_name"));
public class UserData1 {
//...
public String getComp_name(){
return comp_name.get();
}
}
Related
I am trying to insert the information from an excel file to mysql, I am using the extension of springbatch excel to read the file but when trying to insert the mysql it gives an error apparently it does not send the information i shared my batch.config
#Configuration
#EnableBatchProcessing
public class SpringBatchConfig {
#Bean
#Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
public Pagare pagare() {
return new Pagare();
}
#Bean
#Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
public ItemProcessor<Pagare, Pagare> itemProcessor() {
return new PagareItemProcessor();
}
#Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
// dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/pagare");
dataSource.setUsername("root");
dataSource.setPassword("");
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
databasePopulator.addScript(new ClassPathResource("org/springframework/batch/core/schema-drop-mysql.sql"));
databasePopulator.addScript(new ClassPathResource("org/springframework/batch/core/schema-mysql.sql"));
DatabasePopulatorUtils.execute(databasePopulator, dataSource);
return dataSource;
}
#Bean
public BeanWrapperFieldSetMapper<Pagare> beanWrapperFieldSetMapper() {
BeanWrapperFieldSetMapper<Pagare> fieldSetMapper = new BeanWrapperFieldSetMapper<>();
fieldSetMapper.setPrototypeBeanName("pagare");
return fieldSetMapper;
}
#Bean
ItemReader<Pagare> pagareReader() {
PoiItemReader<Pagare> reader = new PoiItemReader<>();
reader.setResource(new ClassPathResource("pagares.xlsx"));
reader.setRowMapper(excelRowMapper());
return reader;
}
private RowMapper<Pagare> excelRowMapper() {
return new RowMapperImpl();
}
#Bean
public BeanPropertyItemSqlParameterSourceProvider<Pagare> beanPropertyItemSqlParameterSourceProvider() {
return new BeanPropertyItemSqlParameterSourceProvider<>();
}
#Bean
public ItemWriter<Pagare> JdbcBatchItemWriter(DataSource dataSource,
BeanPropertyItemSqlParameterSourceProvider<Pagare> sqlParameterSourceProvider) {
JdbcBatchItemWriter<Pagare> jdbcBatchItemWriter = new JdbcBatchItemWriter<>();
jdbcBatchItemWriter.setDataSource(dataSource);
jdbcBatchItemWriter.setItemSqlParameterSourceProvider(sqlParameterSourceProvider);
jdbcBatchItemWriter.setSql("insert into pagare(operacion,id,contrato,tipo,analista,fechaCargaDocumento,estadoOperacion,fechaCambioEstado) values (:operacion, :id, :contrato, :tipo, :analista, :fechaCargaDocumento, :estadoOperacion, :fechaCambioEstado)");
return jdbcBatchItemWriter;
}
#Bean
public Job jobCsvMysql(JobBuilderFactory jobBuilderFactory, Step step) {
return jobBuilderFactory.get("jobCsvMysql").incrementer(new RunIdIncrementer()).flow(step).end().build();
}
#Bean
public Step step1(StepBuilderFactory stepBuilderFactory,
ItemReader<Pagare> pagareReader, ItemWriter<Pagare> writer, ItemProcessor<Pagare, Pagare> processor) {
return stepBuilderFactory.get("step1").<Pagare, Pagare>chunk(6)
.reader(pagareReader).processor(processor).writer(writer).build();
}
}
org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [insert into pagare(test1,id,test3,test4,test5,test6,test7,test8) values (?, ?, ?, ?, ?, ?, ?, ?)]; Column 'id' cannot be null; nested exception is java.sql.BatchUpdateException: Column 'test2' cannot be null
I tried changing the values of my bd and my model and I have the same result, the reason why I use BeanPropertyItemSqlParameterSourceProvider is because my parameters of the insert are equal to those of my property of my model that I leave below
public class Pagare {
private String operacion;
private String rut;
private String contrato;
private String tipo;
private String analista;
private String fechaCargaDocumento;
private String estadoOperacion;
private String fechaCambioEstado;
public String getOperacion() {
return operacion;
}
public void setOperacion(String operacion) {
this.operacion = operacion;
}
public String getTipo() {
return tipo;
}
public void setTipo(String tipo) {
this.tipo = tipo;
}
public String getAnalista() {
return analista;
}
public void setAnalista(String analista) {
this.analista = analista;
}
public String getFechaCargaDocumento() {
return fechaCargaDocumento;
}
public void setFechaCargaDocumento(String fechaCargaDocumento) {
this.fechaCargaDocumento = fechaCargaDocumento;
}
public String getEstadoOperacion() {
return estadoOperacion;
}
public void setEstadoOperacion(String estadoOperacion) {
this.estadoOperacion = estadoOperacion;
}
public String getFechaCambioEstado() {
return fechaCambioEstado;
}
public void setFechaCambioEstado(String fechaCambioEstado) {
this.fechaCambioEstado = fechaCambioEstado;
}
public String getRut() {
return rut;
}
public void setRut(String rut) {
this.rut = rut;
}
public String getContrato() {
return contrato;
}
public void setContrato(String contrato) {
this.contrato = contrato;
}
#Override
public String toString() {
return "Pagare [operacion=" + operacion + ", rut=" + rut + ", contrato=" + contrato + ",tipo=" + tipo + ",analista=" + analista + ",fechaCargaDocumento=" + fechaCargaDocumento + ",estadoOperacion=" + estadoOperacion + ",fechaCambioEstado=" + fechaCambioEstado + "]";
}
my item processor is this
private static final Logger LOG = LoggerFactory.getLogger(PagareItemProcessor.class);
#Override
public Pagare process(Pagare pagare) throws Exception {
LOG.info("Processing " + pagare);
final String initCapAnalista = pagare.getAnalista().substring(0, 1).toUpperCase()
+ pagare.getAnalista().substring(1);
final String initCapTipo = pagare.getTipo().substring(0, 1).toUpperCase()
+ pagare.getTipo().substring(1);
Pagare transformedPagare = new Pagare();
transformedPagare.setOperacion(pagare.getOperacion());
transformedPagare.setAnalista(initCapAnalista);
transformedPagare.setTipo(initCapTipo);
return transformedPagare;
}
}
this picture of console when read the file and error
Since you are using named parameters in your INSERT statement, you need to inject a NamedParameterJdbcTemplate into your writer. Also make sure that the parameter names match the property names of the Pagare type (which you did not share).
This is the generic method through which i am accepting list of
objects and downcasting to a specific object
public Response generate(List<?> list){
List<ClassA> List1 = new ArrayList<ClassA>();
List<ClassB> List2 = new ArrayList<ClassB>();
List<ClassC> List3 = new ArrayList<ClassC>();
if(list instanceof List<?>){
List1=(List<ClassA>) list;//in this line i am getting error
addDataToExcel(List1);
}
else if(list instanceof List<?>){
List2=(List<ClassB>) list;
addDataToExcel(List1);
}
else if(list instanceof List<?>){
List3=(List<ClassC>) list;
addDataToExcel(List1);
}
This is classA
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
#Entity
#Table(name="ClassA")
public class ClassA {
#Id
#Column(name="rollNo")
private int rollNo;
#Column(name="name")
private String name;
#Column(name="english")
private double english;
#Column(name="maths")
private double maths;
#Column(name="science")
private double science;
#Column(name="totalMarks")
private double totalMarks;
#Column(name="percentage")
private double percentage;
#Column(name="status")
private boolean status;
#Lob
#Column(name="file", columnDefinition="BLOB")
private byte[] file;
public ClassA() {
// TODO Auto-generated constructor stub
}
public ClassA(int rollNo, String name, double english, double maths, double science, double totalMarks,
double percentage, boolean status, byte[] file) {
super();
this.rollNo = rollNo;
this.name = name;
this.english = english;
this.maths = maths;
this.science = science;
this.totalMarks = totalMarks;
this.percentage = percentage;
this.status = status;
this.file = file;
}
public int getRollNo() {
return rollNo;
}
public void setRollNo(int rollNo) {
this.rollNo = rollNo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getEnglish() {
return english;
}
public void setEnglish(double english) {
this.english = english;
}
public double getMaths() {
return maths;
}
public void setMaths(double maths) {
this.maths = maths;
}
public double getScience() {
return science;
}
public void setScience(double science) {
this.science = science;
}
public double getTotalMarks() {
return totalMarks;
}
public void setTotalMarks(double totalMarks) {
this.totalMarks = totalMarks;
}
public double getPercentage() {
return percentage;
}
public void setPercentage(double percentage) {
this.percentage = percentage;
}
public boolean isStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
public byte[] getFile() {
return file;
}
public void setFile(byte[] file) {
this.file = file;
}
}
This is the method which accepts List and generate excel
public void add(List<ClassA> classA) {
System.out.println("entering add");
String excelFilePath = "D:/eclipse_neon/StudentInfo.xlsx";
try {
FileInputStream inputStream = new FileInputStream(new File(excelFilePath));
Workbook workbook = WorkbookFactory.create(inputStream);
Sheet sheet = workbook.getSheetAt(0);
int rowNum = 1;
int a=2;
for(ClassA info: classA){
System.out.println("netering loop");
Row row = sheet.getRow(rowNum++);
row.createCell(2).setCellValue(info.getEnglish());
row.createCell(3).setCellValue(info.getMaths());
row.createCell(4).setCellValue(info.getScience());
row.createCell(5).setCellFormula("SUM(C"+a+","+"D"+a+","+"E"+a+")");
row.createCell(6).setCellFormula("("+"F"+a+"*"+"100"+")"+"/"+"300");
row.createCell(7).setCellValue(info.isStatus());
a++;
}
System.out.println("after for loop");
inputStream.close();
FileOutputStream outputStream = new FileOutputStream("D:/eclipse_neon/StudentInfo.xlsx");
workbook.write(outputStream);
workbook.close();
outputStream.close();
} catch (IOException | EncryptedDocumentException
| InvalidFormatException ex) {
ex.printStackTrace();
}
}
I am not able to downcast to my specific List of class from generic list soo any suggestions are welcomed Thankyou
That's probably because you're sending a list as parameter containing a List and class A is not related to LinkedHashMap (not a subclass for example) and therefore it cannot cast. If you can provide more details what is class A and what is the list you're sending as arguments to your method.
Check https://www.baeldung.com/java-type-casting
it's me again. so i have this javafx tableview which i have loaded dynamically with rows and columns from my database. it works out well but there's something i realized. two particular columns in the tableview switch their values. it happened once and when i cancelled the process and ran the program again, it didn't happen, then out of the blues, it happened again. i attached an image so you'd understand better. THANKS GUYS!!
below is the code that populates the tableview with Columns and rows from the database. i don't get any error when i run this.
public void buildData () {
String str = "SELECT * FROM EMPLOYEE_TABLE";
data = FXCollections.observableArrayList();
try {
ResultSet rs = DBaseUtils.dbaseExecuteQuery(str);
for(int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
String columnName = rs.getMetaData().getColumnName(i + 1);
TableColumn<Employee, String> column = new TableColumn<>(columnName);
column.setCellValueFactory(new PropertyValueFactory<>(columnName));
column.setCellFactory(TextFieldTableCell.<Employee>forTableColumn());
column.setOnEditCommit(new EventHandler<>() {
#Override
public void handle(TableColumn.CellEditEvent<Employee, String> event) {
TableColumn<Employee, String> col = event.getTableColumn();
int row = event.getTablePosition().getRow();
ObservableValue<String> observe = col.getCellObservableValue(row);
if (observe instanceof WritableValue) {
((WritableValue<String>) observe).setValue(event.getNewValue());
}
}
});
empTable.getColumns().addAll(column);
}
while(rs.next()) {
Employee emp = new Employee();
emp.setEmployeeId(rs.getString(1));
emp.setFirstname(rs.getString(2));
emp.setLastname(rs.getString(3));
emp.setSex(rs.getString(4));
emp.setEmail(rs.getString(5));
emp.setPhoneNumber(rs.getString(6));
emp.setAddress(rs.getString(7));
emp.setHireDate(rs.getString(8));
emp.setState(rs.getString(9));
emp.setSalary(rs.getString(10));
emp.setDepartment(rs.getString(11));
emp.setSsn(rs.getString(12));
data.add(emp);
}
empTable.setItems(data);
empTable.setEditable(true);
} catch(Exception e) {
e.printStackTrace();
System.out.println("Error building data! ");
}
}
i also attached the model class, well... just in case.
notice the naming conventions for the Property methods, i had to use that because those were the exact names on my database. and since it PropertyValueFactory uses Reflection.
public class Employee {
private SimpleStringProperty employeeId;
private SimpleStringProperty firstname;
private SimpleStringProperty lastname;
private SimpleStringProperty sex;
private SimpleStringProperty email;
private SimpleStringProperty phoneNumber;
private SimpleStringProperty hireDate;
private SimpleStringProperty address;
private SimpleStringProperty state;
private StringProperty salary;
private SimpleStringProperty department;
private SimpleStringProperty ssn;
private long time;
public Employee() {
this.employeeId = new SimpleStringProperty();
this.firstname = new SimpleStringProperty();
this.lastname = new SimpleStringProperty();
this.sex = new SimpleStringProperty();
this.email = new SimpleStringProperty();
this.phoneNumber = new SimpleStringProperty();
this.hireDate = new SimpleStringProperty();
this.address = new SimpleStringProperty();
this.state = new SimpleStringProperty();
this.salary = new SimpleStringProperty();
this.department = new SimpleStringProperty();
this.ssn = new SimpleStringProperty();
}
public String getEmployeeId() {
return employeeId.get();
}
public void setEmployeeId(String id) {
this.employeeId.set(id);
}
public StringProperty EMPLOYEE_IDProperty() {
return employeeId;
}
public String getFirstName() {
return firstname.get();
}
public void setFirstname(String firstname) {
this.firstname.set(firstname);
}
public StringProperty FIRST_NAMEProperty() {
return firstname;
}
public String getLastName() { return lastname.get(); }
public void setLastname(String lastname) {
this.lastname.set(lastname);
}
public StringProperty LAST_NAMEProperty() {
return lastname;
}
public String getSex() {
return sex.get();
}
public void setSex(String sex) {
this.sex.set(sex);
}
public StringProperty SEXProperty() {
return sex;
}
public String getEmail() {
return email.get();
}
public void setEmail(String email) {
this.email.set(email);
}
public StringProperty EMAILProperty() {
return email;
}
public String getPhoneNumber() {
return phoneNumber.get();
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber.set(phoneNumber);
}
public StringProperty PHONE_NUMBERProperty() {
return phoneNumber;
}
public String getHireDate() {
return hireDate.get();
}
public void setHireDate(String date) {
this.hireDate.set(date);
}
public SimpleStringProperty HIRE_DATEProperty() {
return hireDate;
}
public String getAddress() {
return address.get();
}
public void setAddress(String address) {
this.address.set(address);
}
public StringProperty ADDRESSProperty() {
return address;
}
public String getState() {
return state.get();
}
Here's the image. notice the different values in the HIRE_DATE COLUMN AND ADDRESS COLUMN
I am working on deserializing the below JSON:
{"self":"http://members.cs.com/rest/api/user?username=abc#cs.com",
"key":"abc#cs.com",
"name":"abc#cs.com",
"emailAddress":"abc#cs.com",
"displayName":"ABC",
"active":true,
"members":{"size":1,"items":[{"name":"member-users","self":"http://members.cs.com/rest/api/user?username=abc#cs.com"}]},
"expand":"members"}
I have created the following classes:
#JsonIgnoreProperties(ignoreUnknown = true)
public class UserList {
private String name;
private String emailAddress;
private String displayName;
private boolean active;
List<MemberName> members = new ArrayList<>();
#JsonCreator
public UserList(#JsonProperty("name") String name, #JsonProperty("emailAddress") String emailAddress, #JsonProperty("displayName") String displayName, #JsonProperty("active") boolean active, #JsonProperty("members") List<MemberName> members) {
this.name = name;
this.emailAddress = emailAddress;
this.displayName = displayName;
this.active = active;
this.members.addAll(groups);
}
//getters
}
#JsonIgnoreProperties(ignoreUnknown = true)
public class MemberName {
private String name;
#JsonCreator
public MemberName(#JsonProperty("name") String name) {
this.name = name;
}
public String getName() {
return name;
}
}
When I don't give the members as a property the deserialization works fine and I can see the values for the name, displayName, active, emailAddress. The problem happens with the MemberName.
Could someone help with this?
This worked for me:
Class Items as below:
public class Items {
private String name;
private String self;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSelf() {
return self;
}
public void setSelf(String self) {
this.self = self;
}
}
Members class as below:
public class Members {
private int size;
private List<Items> items;
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public List<Items> getItems() {
return items;
}
public void setItems(List<Items> items) {
this.items = items;
}
}
Data class as below:
public class Data {
private String self;
private String key;
private String name;
private String emailAddress;
private String displayName;
private boolean active;
private Members members;
private String expand;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSelf() {
return self;
}
public void setSelf(String self) {
this.self = self;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public Members getMembers() {
return members;
}
public void setMembers(Members members) {
this.members = members;
}
public String getExpand() {
return expand;
}
public void setExpand(String expand) {
this.expand = expand;
}
}
The deserialization as below:
public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
String jsonString = "{\"self\": \"http://members.cs.com/rest/api/user?username=abc#cs.com\",\"key\": \"abc#cs.com\",\"name\": \"abc#cs.com\","
+ "\"emailAddress\": \"abc#cs.com\",\"displayName\": \"ABC\",\"active\": true,\"members\": {\"size\": 1,\"items\": [{"
+ "\"name\": \"member-users\",\"self\": \"http://members.cs.com/rest/api/user?username=abc#cs.com\" }]},\"expand\": \"members\"}";
ObjectMapper mapper = new ObjectMapper();
Data obj = mapper.readValue(jsonString,Data.class);
System.out.println(obj.getSelf());
System.out.println(obj.getKey());
System.out.println(obj.getName());
System.out.println(obj.getEmailAddress());
System.out.println(obj.getDisplayName());
System.out.println(obj.isActive());
System.out.println(obj.getMembers().getSize());
System.out.println(obj.getMembers().getItems().get(0).getName());
System.out.println(obj.getMembers().getItems().get(0).getSelf());
System.out.println(obj.getExpand());
}
How to write hibernate query to get list with below columns which is executed in mysql query executed in jdbc. How to write HQL query in my Main class please let me know
Parent Entity
#Entity
#Table(name = "parent_info")
public class ParentDTO {
#Id
#GenericGenerator(name = "j", strategy = "increment")
#GeneratedValue(generator = "j")
#Column(name = "P_ID")
private int p_id;
#Column(name = "P_NAME")
private String p_name;
#Column(name = "P_PHONE")
private String p_phone;
#Column(name = "P_EMAIL")
private String p_email;
#Column(name = "REF_ID")
private String ref_id;
#OneToMany(cascade={CascadeType.ALL})
#JoinColumn(name="student_id")
private List<StudentDTO> students;
public List<StudentDTO> getStudents() {
return students;
}
public void setStudents(List<StudentDTO> students) {
this.students = students;
}
public int getP_id() {
return p_id;
}
public void setP_id(int p_id) {
this.p_id = p_id;
}
public String getP_name() {
return p_name;
}
public void setP_name(String p_name) {
this.p_name = p_name;
}
public String getP_phone() {
return p_phone;
}
public void setP_phone(String p_phone) {
this.p_phone = p_phone;
}
public String getP_email() {
return p_email;
}
public void setP_email(String p_email) {
this.p_email = p_email;
}
public String getRef_id() {
return ref_id;
}
public void setRef_id(String ref_id) {
this.ref_id = ref_id;
}
}
Student Entity class
#Entity
#Table(name = "student_info")
public class StudentDTO {
#Id
#GenericGenerator(name = "j", strategy = "increment")
#GeneratedValue(generator = "j")
#Column(name = "S_ID")
private int s_id;
#Column(name = "S_NAME")
private String s_name;
#Column(name = "S_PHONE")
private String s_phone;
#Column(name = "S_EMAIL")
private String s_email;
#Column(name = "REF_ID")
private String ref_id;
#Column(name = "S_CLASS_NAME")
private String s_class_name;
#ManyToOne
#JoinColumn(name="parent_id")
private ParentDTO parent;
public ParentDTO getParent() {
return parent;
}
public void setParent(ParentDTO parent) {
this.parent = parent;
}
public int getS_id() {
return s_id;
}
public void setS_id(int s_id) {
this.s_id = s_id;
}
public String getS_name() {
return s_name;
}
public void setS_name(String s_name) {
this.s_name = s_name;
}
public String getS_phone() {
return s_phone;
}
public void setS_phone(String s_phone) {
this.s_phone = s_phone;
}
public String getS_email() {
return s_email;
}
public void setS_email(String s_email) {
this.s_email = s_email;
}
public String getRef_id() {
return ref_id;
}
public void setRef_id(String ref_id) {
this.ref_id = ref_id;
}
public String getS_class_name() {
return s_class_name;
}
public void setS_class_name(String s_class_name) {
this.s_class_name = s_class_name;
}
}
Main class
public class Test {
public static void main(String[] args) {
Session session = null;
Transaction tx = null;
List<StudentDTO> groupList = null;
try {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
session = sessionFactory.openSession();
session.beginTransaction();
session.getTransaction().commit();
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
session.close();
}
}
}
My SQL query executed in jdbc
select pt.P_MOBILE,pt.P_EMAIL, st.S_FIRSTNAME,st.REF_ID from parent_info pt join student_info st on pt.REF_ID = st.REF_ID where st.S_CLASS_TO_JOIN = 10;
String query="paste your query here ";
List<Object[]> objects = session.createSQLQuery(query).list();
ListIterator<Object[]> iterator = objects.listIterator();
while (iterator.hasNext()) {
Object[] object = (Object[]) iterator.next();
int firstcolumn=(Integer) object[0];
int secondcolumn=(Integer) object[1];
}