Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: jdbc program

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default jdbc program

    /*program for implementing Desc command of oracle database in java*/

    import java.sql.*;
    public class jdbc2 {
    	public static void main(String arg[])throws ClassNotFoundException,SQLException
    	{
    		Class.forName("oracle.jdbc.driver.OracleDriver");
    		Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
    		if(con==null)
    		{	System.out.println("sory unable to connect to DataBase " +
    					"Try again after sometime");
                                            return;
                    }
    		else
    			System.out.println("connected successfully");
     
    		String table=arg[0];
    		Statement stmt=con.createStatement();
    		ResultSet rs=stmt.executeQuery("select * from "+ table);
    		ResultSetMetaData rsmd=rs.getMetaData();
    		int n=rsmd.getColumnCount();
    		String s;
    		System.out.println("Name"+"\t\t\t"+"  Null?"+"\t\t\t"+"Type");
    		System.out.println("--------------------    -----------------    --------------");
    		for(int i=1;i<=n;i++)
    		{
     
    			if(rsmd.isNullable(i)==ResultSetMetaData.columnNoNulls)
    				s="  NOT NULL";
    			else
    		        s="          ";
    			if(rsmd.getColumnTypeName(i)=="DATE")
    				System.out.println(rsmd.getColumnName(i)+"\t"+"\t"+"\t"+"\t"+"\t"+rsmd.getColumnTypeName(i));
    			else
    			{
    				if(rsmd.getScale(i)==0)
    			System.out.println(rsmd.getColumnName(i)+"\t"+"\t"+"\t"+
    			       s+"\t"+"\t"+rsmd.getColumnTypeName(i)+
                    			"("+rsmd.getPrecision(i)
    			                   +")");
    				else
    					System.out.println(rsmd.getColumnName(i)+"\t"+"\t"+"\t"+
    						       s+"\t"+"\t"+rsmd.getColumnTypeName(i)+
    			                			"("+rsmd.getPrecision(i)+","
    						                   +rsmd.getScale(i)+")");
    		}}
    		rs.close();
    		rs=null;
    		stmt.close();
    		stmt=null;
    		con.close();
    		con=null;
    }
    }


    compiling and executing of this program
    --------------------------------------------
    1. compile as usual
    2 execute this program by providing table name as command line argument


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: jdbc program

    Do you have a question?

Similar Threads

  1. jdbc
    By vaibz20v in forum JDBC & Databases
    Replies: 1
    Last Post: April 13th, 2013, 11:29 AM
  2. JDBC Problem - com.mysql.jdbc.Driver
    By icu222much in forum Java Servlet
    Replies: 2
    Last Post: November 21st, 2011, 11:54 PM
  3. JDBC
    By Abdul Rasheed in forum JDBC & Databases
    Replies: 1
    Last Post: August 13th, 2010, 07:01 AM
  4. Help with JDBC
    By michaelmel in forum JDBC & Databases
    Replies: 0
    Last Post: May 14th, 2010, 07:11 AM