Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL and JSP connection

Status
Not open for further replies.

shennanigan83

Programmer
Oct 24, 2003
3
PH
hello there! I'm totally new to jsp. could anyone tell me the syntax to connect jsp to MySQL? Thanks a whole lot in advnance!!!
 
Hi,

Make sure you have the mysql-connector-java-3.0.8-stable-bin.jar in your classpath or you can download the driver from mysql.com

Ex :
String url = &quot;jdbc:mysql://<host>/<database>?user=&password=&quot;;
Class.forName(&quot;com.mysql.jdbc.Driver&quot;).newInstance();
java.sql.Connection connection = java.sql.DriverManager.getConnection(url);
java.sql.Statement statement = connection.createStatement();
java.sql.ResultSet columns = statement.executeQuery(query);
while(columns.next())
{
out.println(columns.getString(1));
}



Cheers
-Venu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top