|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
java是一种面向对象的编程语言,优点是可移植性比较高,最初设计时就是本着一次编写到处执行设计的。可以开发各种应用程序和游戏,不过速度没有c++快,所以一般是不用java来编写应用程序和电脑游戏。oracle|历程example1:
/*
*ThissampleshowshowtocallaPL/SQLstoredprocedureusingtheSQL92
*syntax.SeealsotheothersamplePLSQL.java.
*/
importjava.sql.*;
importjava.io.*;
classPLSQLExample
{
publicstaticvoidmain(Stringargs[])
throwsSQLException,IOException
{
//Loadthedriver
DriverManager.registerDriver(neworacle.jdbc.driver.OracleDriver());
Stringurl="jdbc:oracle:oci8:@";
try{
Stringurl1=System.getProperty("JDBC_URL");
if(url1!=null)
url=url1;
}catch(Exceptione){
//Ifthereisanysecurityexception,ignoreit
//andusethedefault
}
//Connecttothedatabase
Connectionconn=
DriverManager.getConnection(url,"scott","tiger");
//Createastatement
Statementstmt=conn.createStatement();
//Createthestoredfunction
stmt.execute("createorreplacefunctionRAISESAL(nameCHAR,raiseNUMBER)returnNUMBERisbeginreturnraise+100000;end;");
//Closethestatement
stmt.close();
//PreparetocallthestoredprocedureRAISESAL.
//ThissampleusestheSQL92syntax
CallableStatementcstmt=conn.prepareCall("{?=callRAISESAL(?,?)}");
//Declarethatthefirst?isareturnvalueoftypeInt
cstmt.registerOutParameter(1,Types.INTEGER);
//WewanttoraiseLESLIEssalaryby20,000
cstmt.setString(2,"LESLIE");//Thenameargumentisthesecond?
cstmt.setInt(3,20000);//Theraiseargumentisthethird?
//Dotheraise
cstmt.execute();
//Getthenewsalaryback
intnew_salary=cstmt.getInt(1);
System.out.println("Thenewsalaryis:"+new_salary);
//Closethestatement
cstmt.close();
//Closetheconnection
conn.close();
}
}
example2:
/*
*Createdon2004-10-12
*
*TODOTochangethetemplateforthisgeneratedfilegoto
*Window-Preferences-Java-CodeStyle-CodeTemplates
*/
/**
*@authorJackey
*
*TODOTochangethetemplateforthisgeneratedtypecommentgoto
*Window-Preferences-Java-CodeStyle-CodeTemplates
*/
/*
*ThissamplecanbeusedtochecktheJDBCinstallation.
*Justrunitandprovidetheconnectinformation.Itwillselect
*"HelloWorld"fromthedatabase.
*/
//Youneedtoimportthejava.sqlpackagetouseJDBC
importjava.sql.*;
//Weimportjava.iotobeabletoreadfromthecommandline
importjava.io.*;
importoracle.jdbc.OracleTypes;
classJdbcCheckup
{
publicstaticvoidmain(Stringargs[])
throwsSQLException,IOException
{
//LoadtheOracleJDBCdriver
DriverManager.registerDriver(neworacle.jdbc.driver.OracleDriver());
//Prompttheuserforconnectinformation
System.out.println("Pleaseenterinformationtotestconnectiontothedatabase");
Stringuser;
Stringpassword;
Stringdatabase;
user=readEntry("user:");
intslash_index=user.indexOf(/);
if(slash_index!=-1)
{
password=user.substring(slash_index+1);
user=user.substring(0,slash_index);
}
else
password=readEntry("password:");
database=readEntry("database(aTNSNAMEentry):");
System.out.print("Connectingtothedatabase...");
System.out.flush();
System.out.println("Connecting...");
Connectionconn=DriverManager.getConnection
("jdbc:oracle:oci8:@"+database,user,password);
System.out.println("connected.");
//Createastatement
Statementstmt=conn.createStatement();
//DotheSQL"HelloWorld"thing
ResultSetrset=stmt.executeQuery("selectHelloWorldfromdual");
while(rset.next())
System.out.println(rset.getString(1));
//closetheresultset,thestatementandconnect
rset.close();
stmt.close();
System.out.println("YourJDBCinstallationiscorrect.");
//
CallableStatementcall=conn.prepareCall("{callEmp_dept_data.Open_cv(?,?)}");
//FindoutalltheSALESperson
//call.registerOutParameter(1,OracleTypes.CURSOR);
call.registerOutParameter(1,OracleTypes.CURSOR);
call.setInt(2,1);
call.execute();
ResultSetrs=(ResultSet)call.getObject(1);
//Dumpthecursor
while(rs.next())
System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));
rs.close();
call.close();
conn.close();
}
//Utilityfunctiontoreadalinefromstandardinput
staticStringreadEntry(Stringprompt)
{
try
{
StringBufferbuffer=newStringBuffer();
System.out.print(prompt);
System.out.flush();
intc=System.in.read();
while(c!=
&&c!=-1)
{
buffer.append((char)c);
c=System.in.read();
}
returnbuffer.toString().trim();
}
catch(IOExceptione)
{
return"";
}
}
}
j2EE和asp比较,其实也没什么比的,原因和我上面说那些比较差不了多少,也是稳定性,安全性,J2EE比asp高,速度上比不过asp,asp也是延续着它的拖拽控件的方法,提高速度。 |
|