File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes MySql with JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "MySql with JSP" Watch "MySql with JSP" New topic

MySql with JSP

Eduardo Tusco

Joined: May 09, 2003
Posts: 5
How can I connect MySql DB with JSP? Do I need a specific JDBC or ODBC?
And I don�t know how to set MySql up in my WinXP!!!
Could you help? Thanks in advance!
Joe Ess

Joined: Oct 29, 2001
Posts: 9188

MySQL has some excellent documentation, including a chapter on Installing on Windows. As for connecting to a database, have you used JDBC before? If not, check out the tutorials in the JDBC Documentation. JSP pages get compiled into servlets so you can use JDBC in them like you would in any other Java program.

[How To Ask Questions On JavaRanch]
Annemarie McKeown
Ranch Hand

Joined: Nov 07, 2003
Posts: 47
Very simple something like the following will connect to your database and allow you to submit a query...
assuming homework is the name of the database and the user name is root.
Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost/homework?user=root");
Statement stmt = myConn.createStatement();
stmt.executeUpdate("some query....");
You'll also need a mysql-connector.jar downloaded and installed in your webapp.
Hope this helps.
[ March 01, 2004: Message edited by: Annemarie McKeown ]
It is sorta covered in the JavaRanch Style Guide.
subject: MySql with JSP
It's not a secret anymore!