Tuesday, 8 January 2013

JDBC in Java Example

Simple Example for JDBC in Java

import java.sql.*;

public class clsDatabase 
public static void main(String args[]) 
    // URL for where the database is
String url = "jdbc:postgresql://localhost:5432/interview";
 // Load the postgres driver
    catch( Exception e )
     System.out.println("Failed to load mSQL driver.");
    try {

   // Get the connection object using the drivermanager class
  Connection con = DriverManager.getConnection(url, "postgres", "pass@1234!@#$");

      // create a statement object using the connection object
      Statement select = con.createStatement();

      // get the resultset by firing the query using the statement object
      ResultSet result = select.executeQuery("Select * from users");         

      // loop through the resul object and display the name field
        String key = result.getString(1);
    catch( Exception e ) 

Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

1 comments : on " JDBC in Java Example "

mary Brown said...

I have read your blog its very attractive and impressive. I like it your blog.

Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

Online Java Training Online Java Training | Java J2EE Online Training | JavaEE Training Institute in Chennai

Post a Comment

Popular Posts