6
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by peter_budo
0

There are a choke full of online resources out there for the same. A simple google search for "connect to oracle using java" should be good to go.

-2
import java.io.*;
import java.sql.*;
import java.net.*;

public class sqlDemo1
{
	int eno;
	ResultSet rs;
	ResultSetMetaData md;
	String /*insq,*/ selq;
	Statement stmt;
	
	public sqlDemo1()
	{
		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			Connection con=DriverManager.getConnection("jdbc:odbc:javadb");
			
			//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			//System.out.println("Enter Employee id");
			//eno=Integer.parseInt(br.readLine());

			stmt=con.createStatement();
			selq="select * from emp";
			

			//insq="insert into emp values(?,?,?)";
			//int j=stmt.executeUpdate(insq);
			//System.out.println("No of rows inserted \t" +j);
			
			rs=stmt.executeQuery(selq);
			md=rs.getMetaData();
			int col=md.getColumnCount();
			
			while(rs.next())
			{
				for(int i=0; i <= col; i++)
				{
					System.out.print(rs.getString(i) + "\t");
					//rs.next();
				}
				System.out.println();
			}
		
			rs.close();
			stmt.close();
			con.close();
		}
		
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public static void main(String args[]) throws Exception
	{
		new sqlDemo1();
	}
}

Edited by ~s.o.s~: Added code tags, please learn to use them.

Comments
don't help homework kiddos with free code
No code tags and not the best example
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.