| | |
Simple Command Line interface -
![]() |
•
•
Join Date: May 2005
Posts: 1
Reputation:
Solved Threads: 0
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?
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();
}
}
You could use a select statment or the command design patten.
http://www.dofactory.com/Patterns/PatternCommand.aspx
http://www.dofactory.com/Patterns/PatternCommand.aspx
![]() |
Similar Threads
- Can we execute command line cmds from a php file?? (PHP)
- SQL Plus command line: Arrow keys not giving previous commands back (Oracle)
- Help with Creating a Command Line Menu (C++)
- simple help (Java)
- Trouble w/ Borland command line tools. (C++)
- command line (OS X)
Other Threads in the Java Forum
- Previous Thread: Finding Open Ports
- Next Thread: Multiple Classes
| Thread Tools | Search this Thread |
-xlint add android api applet application array arrays automation bi binary blackberry block bluetooth class client code compile compiler component database developmenthelp eclipse equation error event fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image int integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loops mac main map method methods mobile myregfun netbeans nonstatic notdisplaying number online pearl problem program project qt recursion scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor




oracle:1521: ora1","", "");
