This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes how to access database using jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how to access database using jsp" Watch "how to access database using jsp" New topic
Author

how to access database using jsp

bhaskar reddy.b
Greenhorn

Joined: Jan 21, 2002
Posts: 8
please give me an example program that access the database and displays a record from the specified table.
database is db2 or mysql.
please anybody can just paste an example .
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
a good example from sun here (you need to have adobe).
Database - JSP example
Sals Hamid
Greenhorn

Joined: Jan 04, 2002
Posts: 24
import java.sql.*;
class MyFirstDB
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //Load Drivers

Connection con=DriverManager.getConnection("jdbc dbc:xyz");//Open connection
Statement stm=con.createStatement();
//To keep records we have another interface ResultSet
ResultSet rs = stm.executeQuery("select * from product");
while(rs.next())// next is method of ResultSet
System.out.println(rs.getString("productID")+""+rs.getString("productName")+""+rs.getString("price"));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}


No Path of Flowers lead to glory
Sals Hamid
Greenhorn

Joined: Jan 04, 2002
Posts: 24
import java.sql.*;
class MyFirstDB
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //Load Drivers

Connection con=DriverManager.getConnection("jdbc dbc:xyz");//Open connection
Statement stm=con.createStatement();
//To keep records we have another interface ResultSet
ResultSet rs = stm.executeQuery("select * from product");
while(rs.next())// next is method of ResultSet
System.out.println(rs.getString("productID")+""+rs.getString("productName")+""+rs.getString("price"));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
 
wood burning stoves
 
subject: how to access database using jsp
 
Similar Threads
about DatemodelDbImpl and model !!
Connection to Dbase
how to connect to database in FORTE ---"3.0"---
connecting MIDlet to database?
How to connect a database from Servlet/Jsp, EJB