Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to access database using jsp

 
bhaskar reddy.b
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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 .
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a good example from sun here (you need to have adobe).
Database - JSP example
 
Sals Hamid
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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
  • 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();
}
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic