| | |
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
Views: 6264 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
access actionlistener android applet arguments array arraylist arrays binary build c# chat class classes client code combobox compile component converter coordinates data database db design detection eclipse error event exception fast file filei/o givemetehcodez graphics gui helpwithhomework html ide image images inheritance input j2me java jframe jmf jni jpanel jtextfield julia linked linked-list list loop looping main method mobile netbeans newbie number object objects oracle page pattern phone pixel problem program programming read recursion remove return robot scanner server service set sms software sort source sql string swing system test text text-file thread threads time timer translate tree user web




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