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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to connect to an SQL database.

Status
Not open for further replies.

4345487

Programmer
Dec 31, 2002
132
0
0
US
Hi,

I'm trying to learn JSP and I would like if someone has an example of how to connect and get data from a SQl database.


Thanks in advance

 
Basically I use this:

{
Class.forName("com.mysql.jdbc.Driver");
Connection myConn=DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=root");
Statement stmt = myConn.createStatement();

String query = "SELECT count(messageNr) FROM messages";

ResultSet resultaat = stmt.executeQuery( query );

while(resultaat.next())
{
String GetIT = resultaat.getString("count(messageNr)");
out.println(" "+GetIT+"");
}
}

Note that you need the MySQL connector JAR installed...

greetz,
Menno.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top