JDBC

Started by beingchinmay, 10-26-2016, 05:03:51

Previous topic - Next topic

beingchinmayTopic starter

The JDBC standard defines an application program interface (API) that Java programs can use to connect to database servers. (The word JDBC was originally


public static void JDBCexample(String userid, String passwd)
{
try
{
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@db.yale.edu:1521:univdb",
userid, passwd);
Statement stmt = conn.createStatement();
try {
stmt.executeUpdate(
"insert into instructor values('77987', 'Kim', 'Physics', 98000)");
} catch (SQLException sqle)
{
System.out.println("Could not insert tuple. " + sqle);
}
ResultSet rset = stmt.executeQuery(
"select dept name, avg (salary) "+
" from instructor "+
" group by dept name");
while (rset.next()) {
System.out.println(rset.getString("dept name") + " " +
rset.getFloat(2));
}
stmt.close();
conn.close();
}
catch (Exception sqle)
{
System.out.println("Exception : " + sqle);
}
}