Topic: 如何执行这个select命令?

  Print this page

1.如何执行这个select命令? Copy to clipboard
Posted by: wind9
Posted on: 2003-12-17 13:48

java>java Select(注,这里是Select.class) id=1
然后出现和id=1的相适应的情报

就是直接在javac Select.java生成的Select.class,在java Select 命令的同时
执行Select.java里面的select命令?那么怎么在Select.java里面main里面写程序?

2.Re:如何执行这个select命令? [Re: wind9] Copy to clipboard
Posted by: dingligang
Posted on: 2003-12-21 15:04

maybe the following can help you ...

Class Select{
//
//... ... your java code
//
puclic static void main(String[] args){
String id = null;
if(args!=null&&args.length>0){
id = args[0];
}else{
id = null; //or other you wanted
}
//
//... ... your other java code
//
}
}


java>java Select 1

3.Re:如何执行这个select命令? [Re: dingligang] Copy to clipboard
Posted by: wind9
Posted on: 2003-12-22 13:26

import java.sql.*;
import java.math.*;
import java.io.*;

public class Select {
public static void main(String args[]) {
String url = "jdbc:oracle:thin:@:1521:orc1";
Connection con=null;

try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
con=DriverManager.getConnection(url,"","");
Statement select = con.createStatement();
ResultSet result = select.executeQuery
("select * from STUDENT00231");

System.out.println("result");

while(result.next()) {
int key;
String val;
key = result.getInt(1);
if ( result.wasNull()){
key=-1;
}
val = result.getString(2);
if (result.wasNull()) {
val=null;
}
System.out.println("key = " + key);
System.out.println("val = " + val);
}
}
catch(Exception e) {
e.printStackTrace();
}
finally {
if (con != null) {
try { con.close();}
catch(Exception e) {
e.printStackTrace();
}
}
}
}
}


我想要这样执行命令
sql>java Select STUDENT_CODE=1
然后出来结果


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923