|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
但是对于JAVA技术类的学习,我觉得大课堂反而会影响自身独立思考的过程,因为上课的时候,老师讲课的速度很快为了不遗漏要点,通常会仔细的听,链接|数据|数据库packagespider.tools;
importjava.sql.*;
publicclassDBTools{
publicstaticfinalintORACLE=0;
publicstaticfinalintSQLSERVER=1;
privatestaticStringoracleDriver=
"oracle.jdbc.driver.OracleDriver";
privatestaticStringsqlserverDriver=
"com.microsoft.jdbc.sqlserver.SQLServerDriver";
publicConnectioncreateConnection(Stringhost,StringdataBase,Stringuser,Stringpassword,
intdbKind){
Connectionresult=null;
StringdbUrl=null;
StringdbDriver=null;
if(dbKind==ORACLE){
dbUrl=createOracleUrl(host,dataBase);
dbDriver=oracleDriver;
}
elseif(dbKind==SQLSERVER){
dbUrl=createSqlserverUrl(host,dataBase);
dbDriver=sqlserverDriver;
}
else{
MyUtil.log(
"initialdatabaseconnectionfailure:"+"Unsupportdatabase!");
returnnull;
}
try{
Class.forName(dbDriver);
result=DriverManager.getConnection(dbUrl,user,password);
}
catch(Exceptione){
MyUtil.log(
"initialdatabaseconnectionfailure:"+e.toString());
returnnull;
}
returnresult;
}
publicStringcreateOracleUrl(Stringhost,StringdataBase){
StringoracleUrl="jdbc:oracle:thin:@"
+host+":1521:"
+dataBase;
returnoracleUrl;
}
publicStringcreateSqlserverUrl(Stringhost,StringdataBase){
StringsqlServerUrl="jdbc:microsoft:sqlserver://"
+host+":1433;DatabaseName="
+dataBase;
returnsqlServerUrl;
}
publicbooleanisTableExist(Connectioncnn,Stringtable){
booleanresult=false;
StringstrSQL="select*fromsysobjectswhereid=object_id("+table+")";
Statementst=null;
ResultSetrs=null;
try{
st=cnn.createStatement();
rs=st.executeQuery(strSQL);
if(rs.next())
result=true;
}
catch(SQLExceptionex){
MyUtil.log("Errorhappenwhenchecktableexistance!tablename:"+table);
}
finally{
if(st!=null){
try{
st.close();
}
catch(SQLExceptionex1){}
}
if(rs!=null){
try{
rs.close();
}
catch(SQLExceptionex1){}
}
}
returnresult;
}
publicbooleanclearTable(Connectioncnn,Stringtable){
if(!isTableExist(cnn,table))
returnfalse;
booleanflag=true;
PreparedStatementps=null;
try{
ps=cnn.prepareStatement("deletefrom"+table);
ps.executeUpdate();
}
catch(Exceptione){
flag=false;
}
finally{
if(ps!=null){
try{
ps.close();
}
catch(SQLExceptionex){}
}
}
returnflag;
}
}
C#跟java类似,但是在跨平台方面理论上可以跨平台,实际上应用不大,执行性能优于java,跟C++基本一致,但是启动速度还是慢.代码安全,但容易性能陷阱. |
|