i want to connect jsp with mysql ,
plz send me the connectivity code or any connectivity program...............

no you don't.
You want to use a servlet.
But before that you want to work through the jdbc tutorial and the jee tutorial on Sun's website.

Try using the following code as a db connection model.

Once done, call


from within which ever file you are trying to get the db connection from

public class database {

    private Connection connection;
    private static String databaseName = "******";
    private static String databaseUsername = "******";
    private static String databasePassword = "******";
    private static String driver = "com.mysql.jdbc.Driver";

    public Connection getConnection() {
        return connection;

    public void createConnection() {
        if (connection == null) {
            try {
                String url = "jdbc:mysql://localhost:3306/" + databaseName;

                connection = DriverManager.getConnection(
                        url, databaseUsername, databasePassword);

            } catch (Exception e) {
                JOptionPane.showMessageDialog(new JFrame(),
                        "Database connection could not be established.  Please" +
                        "check your network connection and restart.",
                        "Error Message",
                connection = null;

which is of course exactly what you DON'T want to do.

@jwenting, curious as to why i shouldn't be using this method?

What would you recommend?

See above. Do NOT do database actions in a JSP.
Do NOT use globals to store open database connections etc.

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.