JDBC Tutorial For M.SC (IT)
JDBC Tutorial For M.SC (IT)
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
Here Rakhi is the DNS which you have created in the control pannel with the help
of ODBC
Create Connection Object:
Using a database URL with a username and password:
DriverManager.getConnection() method is used to create a connection object.
The most commonly used form of getConnection() requires you to pass a database
URL, a username, and a password:
con = DriverManager.getConnection(url, userid, password);
System.out.println(rs.getInt(1) + "\t" +
rs.getString(2)+ "\t\t" +rs.getFloat(3)+"\t"
+rs.getDate(4)+"\t"+rs.getFloat(5));
}
Prepared By Prof. Rakhi Budhrani
Prepared By Prof. Rakhi Budhrani
Closing
• At the end of your JDBC program, it is required
explicitly close all the connections, statements,
recordsets to the database to end each database
session.
• rs.close();
• st.close();
• cn.close();
• For more details visit:
http://www.tutorialspoint.com/jdbc/index.htm
Prepared By Prof. Rakhi Budhrani