Simple Command Line interface -

Reply

Join Date: May 2005
Posts: 1
Reputation: morgryan is an unknown quantity at this point 
Solved Threads: 0
morgryan morgryan is offline Offline
Newbie Poster

Simple Command Line interface -

 
0
  #1
May 6th, 2005
Hi there

I need to create a command line interface in java. I have something that connects to an oracle database and allows me to do a predetermined select steps. I need some sort of java code that will allow me to have a prompt:

Which you like to do?
1 - input fields into the table?
2 - delete the table
etc....
PLEASE SELECT NUMBER

And then excute the multiple sql commands - I know the commands i just need the structure for the java program - where to put them and how to calll them if the user inputs a value of "1" say. I have an example below - this allows you to just run one command - any ideas how this could be expanded?

import java.sql.*;

public class JDBCEmp
{
public static void main( String args[] ) throws Exception
{
// Find the class...
Class.forName( "oracle.jdbc.driver.OracleDriver" );

// Open a connection...
Connection myConnection = DriverManager.getConnection(
"jdbc: oracle:thinoracle:1521: ora1","", "");

// Create a statement...
Statement myStatement = myConnection.createStatement();

// Execute a query...
try
{
// Execute the query...
myStatement.execute( "select * from EMP where EMPNO between 7499 and 7788" );

// Get the result set...
ResultSet mySet = myStatement.getResultSet();

// Advance to the next row...
while ( mySet.next() )
{
// Get the data...
int empno = mySet.getInt( "empno" );
String ename = mySet.getString( "ename" );
long salary = mySet.getLong( "sal" );

// Print it all out...
System.out.println( Integer.toString( empno ) + " - " +
ename + " - " + Long.toString( salary ) );
}
}
catch ( SQLException e )
{
System.out.println( "SQL Error: " + e.toString() );
}

// Close everything up...
myStatement.close();
myConnection.close();
}

}
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 181
Reputation: Paul.Esson is an unknown quantity at this point 
Solved Threads: 10
Paul.Esson's Avatar
Paul.Esson Paul.Esson is offline Offline
Junior Poster

Re: Simple Command Line interface -

 
0
  #2
May 7th, 2005
You could use a select statment or the command design patten.

http://www.dofactory.com/Patterns/PatternCommand.aspx
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 6264 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC