Sponsered Links
Categories
Sponsered Links

JDBC Connection Example

 

This is a simple JDBC connection Example.

import java.sql.*;

public class JDBCon {
    public static void main(java.lang.String[] args) {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch (ClassNotFoundException e) {
            System.out.println("Unable to load Driver Class");
            return;
        }

        try {
            Connection dbcon = DriverManager.getConnection("jdbc:odbc:db1","", "");
            Statement smnt = dbcon.createStatement();
            ResultSet res = smnt.executeQuery("SELECT ENAME FROM EMP");
            while(res.next()) {
                System.out.println(res.getString("ENAME"));
            }
            res.close();
            smnt.close();
            dbcon.close();
        } catch (SQLException se) {
            System.out.println("SQL Exception: " + se.getMessage());
            se.printStackTrace(System.out);
        }
    }
}

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved