把你的信息作成一个配置信息的文件,通过读取指定文件中的有关参数设置来获取
有关的值就可以那!
在文件中xxx.conf以:
className="";
connString="";
userName="";
password="";
存储
String re = readfile("xxx.conf");
className=re.getValue(className);
.....你关键就是设定好读取文件的readfile的方式和以及得到结果的形式!
有关的值就可以那!
在文件中xxx.conf以:
className="";
connString="";
userName="";
password="";
存储
String re = readfile("xxx.conf");
className=re.getValue(className);
.....你关键就是设定好读取文件的readfile的方式和以及得到结果的形式!
main.server=RDSERVER
main.port=1433
main.database=KE36
main.user=sa
main.password=sa###################ORACLE###############
oracle.type=ORACLE
oracle.server=192.168.0.100
oracle.port=1521
oracle.database=kenoah
oracle.user=kenoah33
oracle.password=kenoah33
#########################################
import java.sql.*;
import java.lang.*;
import java.io.*;
import java.util.*;
public class ExportWfActivityDefinition {
Connection conn = null;
ResultSet rs = null;
Properties kenoahSystem = new Properties();
private Connection getConn(){
try{
kenoahSystem.load(new FileInputStream("properties/kenoahSystem.properties"));
}
catch(IOException e ){System.out.println(e);}
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String serverName = (String)kenoahSystem.get("main.server");;
String portNumber = (String)kenoahSystem.get("main.port");
String databaseName = (String)kenoahSystem.get("main.database");
String database = serverName + ":" + portNumber + ";databaseName=" + databaseName;
String url = "jdbc:microsoft:sqlserver://"+database;;
String username = (String)kenoahSystem.get("main.user");
String password = (String)kenoahSystem.get("main.password");
Connection connection = null;
try{
Class.forName(driverName);
connection = DriverManager.getConnection(url,username,password);
}
catch(Exception e){System.out.println(e);}
return connection;
} private ResultSet getRS(Connection conn){
Statement stmt = null;
ResultSet resulset = null;
try{
stmt = conn.createStatement();
String sql = "select activitydefid,jobfuncid,userid from WfActivityDefinition where ActivityDefID>10000";
resulset = stmt.executeQuery(sql);
}
catch(Exception e){System.out.println(e);}
return resulset;
} public void execute(){
conn = this.getConn();
rs = getRS(conn);
StringBuffer sb = new StringBuffer("");
try{
while(rs.next()){
String id = rs.getString(1);
String jobfuncid = rs.getString(2);
String userid = rs.getString(3);
sb.append("update WfActivityDefinition set jobfuncid=" + jobfuncid);
sb.append(",userid=" + userid + " where activitydefid="+ id);
sb.append("\n");
}
BufferedWriter out = new BufferedWriter(new FileWriter("exportWfActivityDef.sql"));
out.write(sb.toString());
out.close();
}
catch(Exception e){ System.out.println(e);}
} public static void main(String[] args) {
ExportWfActivityDefinition exportobj = new ExportWfActivityDefinition();
exportobj.execute();
}}
{
String[] fileContent=null;
//读取文件内容
String content="";
File file=new File(ff);
if(!file.exists())
{
//文件不存在
System.out.println("File not Exists!");
return null ;
}
else if (file==null)
{
//未知错误
System.out.println("UnKnown Error!");
return null ;
}
else
{
//文件存在
try
{
BufferedReader reader = new BufferedReader(new FileReader(file));
String inLine=reader.readLine();
while(inLine!=null)
{
content+=inLine;
inLine=reader.readLine();
}
reader.close();
}catch(IOException ex)
{
System.out.println("IOException is "+ex);
return null ;
}
}
//解析文件标签
fileContent=content.split(";");
int i=0,j=0;
for(int k=0;k<4;k++)
{
i=fileContent[k].indexOf("=\"");
fileContent[k]=fileContent[k].substring(i+2);
i=fileContent[k].indexOf("\"");
fileContent[k]=fileContent[k].substring(0,i);
}
return fileContent;
}文件内容:
className="haha" ;
connString="hhee" ;
userName="heihe" ;
password="hengheng";
就可以用put get方法直接操作文件,