• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to access database using jsp

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a good example from sun here (you need to have adobe).
Database - JSP example
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
}
 
Sals Hamid
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic