Program for entering 1000 random numbers into two different databases, one for odd numbers and one for even
Structure your code


Name your variables appropriately! It is not a good idea to have the connections called con and conn. Likewise ps and ps3 are not good names for your prepared statements. It will confuse you when trying to debug this.
Make a method that inserts a value into a database.
Do not catch Exception. Make sure you know what exception you catch and why. Right now you declare your main to throw exceptions, but I don't think it really does.


Prepared statements are reusable

You prepare a statement to let the database optimize for it. It takes a bit of time, but it saves time when you use it. What you do, is you prepare the statement inside your loop, making it a lot slower. Move the preparation of your statement

PreparedStatement ps = con.prepareStatement("insert into try values (?)");


outside your loop. This will make your program run faster.

Random is reusable

You create a new instance of Random on every rotation of the loop. Move this outside the loop - it will make your code run faster.

Remove unnecessary things

Your code is littered with statements executing expensive methods to no use.

What does

Class.forName("com.mysql.jdbc.Driver");


do?

What is the purpose of

ps.addBatch();
breakcon = breakcon + 1;
if (breakcon % 500 == 0 || breakcon == val)
  ps.executeBatch();


What is the purpose of oddcount and evencount?