0

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

3
Contributors
5
Replies
7
Views
7 Years
Discussion Span
Last Post by jwenting
0

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.

-1

Try using the following code as a db connection model.

Once done, call

database().getConnection();

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() {
        createConnection();
        return connection;
    }

    public void createConnection() {
        if (connection == null) {
            try {
                Class.forName(driver);
                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",
                        JOptionPane.ERROR_MESSAGE);
                e.printStackTrace();
                connection = null;
            }
        }
    }
}
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.