-
Java (
http://www.daniweb.com/forums/forum9.html)
| morgryan | May 6th, 2005 1:36 pm | |
| Simple Command Line interface - 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?
Quote: 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:thin:@oracle: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();
}
} | |
| Paul.Esson | May 7th, 2005 12:03 pm | |
| Re: Simple Command Line interface - |
| All times are GMT -4. The time now is 1:47 am. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC