in my each jsp page i have to write this code to connect with Mysql database

Class.forName("com.mysql.jdbc.Driver").newInstance();
String url ="jdbc:mysql://35.212.176.25/tri";
Connection con = DriverManager.getConnection(url,"root", "");

now i want to make this code in a separate jsp page and then only include this page in my current jsp page where ever necessary to connect with my Database like in PHP. Is it possible in Jsp . If yes pls tell me

You should move it out to a Servlet, bean, custom JSTL tag, or other application context item. This type of code should never be found in a JSP.

Other than that, yes it is possible.

Try going through the following:
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/
(although it is one version outdated now)

yes it's possible and no we're not going to tell you how to do it as it is (as you've already been told) extremely bad to do so.

It is in fact one of the reasons PHP is frowned upon by people who are serious about writing software rather than quickly hacking something together in the hope noone will ever have to change it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.