Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!

Mandar Khire

Ranch Hand
+ Follow
since Sep 11, 2007
Mandar likes ...
Android Java Linux
Pune, Maharashtra,India
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mandar Khire

Additional info:-
I download MySql Connector for above program from following Link:-
Connector/J 5.1.45

I found 'mysql-connector-java-5.1.45-bin.jar' file which I use as Library.
If I not use that then I got Exception as follow:-

I updated Java today & after it, I am facing exception.
My Java version is

I wrote very basic program.

Got Exception as follows:-

Need Expert's Help.

What should I write in for loop to print values?

Don't you have an IDE?

I am using Eclipse IDE Oxygen.1a Release (4.7.1a).

Here I post 4 Screenshots:-
1. resultList

2. get_combined_two_tables()

3. combined_table_List

4. java.lang.ArrayStoreException
I put Breakpoint & try to find out where I get problem.
I got following result when I put break point at 'combined_table_List = get_combined_two_tables("Mandar");'

I got following Result when I put breakpoint at 'System.arraycopy(combined_table_List, 0, dest, 0,combined_table_List.get(i).toString().length());'

Still not understand why following line fail

You will need to cast to read them.

Normally I cast as follows when I fetch table1 & table2 separately in table1_List & table2_List:-

But when when I get result from combined 2 tables then how to cast List to read them?
Copying Array is right way to do that?
Thanks Dave Tolls,

I have no idea what these lines are supposed to be doing:

I implement given code & got following exception.

Got print following line:-

Now how to solve it?
Thanks Dave Tolls,
Using following code I get no error in java program:-

But I got problem when I try to convert Object Array for print values.

When I print combined_table_List.size() & comment for loop. then Got following output, without exception.

As I understand now no need to cast table1 or table2, in for loop with combined_table_List, to print column values right?
Then how to print values from Object List?
Need more guidance to print 4 variables from table1 & table2.
1. My Query work in Mysql as below:-

I used it in Java program as follows:-

I fetch List in java as follows:-

I declared List as follows:-

Now problem is how I fetch values from this List (combined_table_List)& print it?

2. ":name" in query I tried in Mysql but it show Syntax error. I dont know about how to write query using ":", so I cant use it in Java program.

Need help.
Thanks Dave Tolls,

This is the query you are apprently trying to duplicate.
Since you need both table 1 and 2, thenthe HQL would start:

That will return a List<Object> where each row is an array of two Objects, the first is a table1 and the second is a table2.

Not the use of the bind variable ':name', instead of concatenating your SQL.
You ought to be using bind variables

I tried above but not understand it, or not find a way to implement in java.
Can you give me example 1. query in Mysql 2. What should I write in Java so I can print values?
I found 1 way to solve this problem.
I fetch table in List, then I create List for each column, & compare it & print results which I need.
But currently tables are very small, if rows in tables increases then Lists also get bigger & it will trouble memory issue(I thought).

Following is program:-
Thanks Dave Tolls,
I want all 4 values (2 from each table ie all columns) to show in print statement, but there is condition as follows:-
Condition is
1. if Table2.column2 value match with "Mandar" then select that line.
2. If Table1.column1 value match with table2.column1 value then select that line also.
3. Now print all columns from all tables which satisfy above two conditions.

Table values as follows:-


As per my 2 conditions I can say, in table2 there are 4 times word "Mandar", so as per 2nd line of condition I have to fetch 4 lines from table1 along with table2.

For that I change my program as follows:-

But when I not pass table2.column1 value to query which fetch table1's values, then I get table2's all line which match with word "Mandar".
I confuse to solve this.
I not understand how to do that.
Need Help.
I am trying to fetch data from 2 tables by Java, hibernate & Mysql.
I have 2 tables, table1 & table2.
table1 has 3 Columns say rowindex, column1, column2.
table2 has 3 Columns say rowindex, column1, column2.
table1 & table2 have column1 values same but both have different values in column2.

Question is How to show result in java as common_column, table1_column2, table2_column2, when for search input is table2.column2 value (String) say my name "Mandar".

For that First I try query in Mysql.

It give me result as I want when I put above query in Mysql Workbench.

I write Java Program for find out how to solve this but failed.

Here I put my complete test_db project created for example.







7. hibernate1.cfg.xml

8. jdbcdetails.xml

9. table1.hbm.xml

10. table2.hbm.xml

By above program, I got Exception as follows:-

Need help.

Campbell Ritchie wrote:
Why? If you are creating an empty List, what is wrong with myList = new XYZList<>();? Why did you choose a linked list rather than an array list?

I tried LinkedList by reading Stackoverflow.
Then my example works, Also My actual working code also works.

Now I am searching root cause of why Linkedlist works & why Arraylist not works.

If anyone know root cause then it will helpful for understand basics better way.
4 months ago
Thanks Campbell Ritchie,
I got answer my self. I forgot points given in How To Ask Questions On Java Ranch.
I change


4 months ago