JDBC中怎样隐藏数据库的名字
解决方案 »
- telnet字符串显示问题
- 我的netbeans7.0运行Java程序,输入英文没问题,为什么输入中文出问题了?
- java strgin类赋值疑问
- 一个关于hibernate存取数据的问题,很急啊,分不够就加!!!
- 请问一下高手:Vector和ArrayList方法的怎么用啊?并且各有什么优缺点?
- 求解:写一个程序做低于256位整数的运算
- JGraph如何实现画圆?
- 关于FileOutputStream (答案选社么,原因)
- package Oracle.jdbc does not exist,找不到原因!!
- 我想验证一下线程不同步时,成员变量会一致时
- 先看,看了再说好不好...
- 我作拉个简单考试的程序,有5个类,我分成5个文件,程序有点问题,我问老师,他就显示出和以前一样的态度——“哦,我忘记看拉,过几天给
package pputil;import java.io.*;
import java.util.*;/**
* <p>Title: FileProperty</p>
* <p>Description: 从文件读Property值</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: ZSU</p>
* @author Phil
* @version 1.0
*/public class FileProperty
extends Properties {
private String fileName = null;
private InputStream inStr = null;
private OutputStream outStr = null; /** 由给定的文件名构造类 */
public FileProperty(String loadsaveFileName) throws IOException {
super();
fileName = loadsaveFileName;
load();
} /**
* 从指定的文件载入属性值,如果失败,确保后缀名为".properties",
* 然后再重试一次
*/
public void load() throws IOException {
try {
if (inStr == null) {
inStr = new FileInputStream(fileName);
}
}
catch (FileNotFoundException fnf) {
if (!fileName.endsWith(".properties")) {
inStr = new FileInputStream(fileName + ".properties");
// 如果成功,则记住改变后的文件名
fileName += ".properties";
}
else { // 否则抛出错误
throw fnf;
}
}
//调用超类的load函数
load(inStr);
} /** 保存属性值 */
public void save() throws IOException {
if (outStr == null) {
outStr = new FileOutputStream(fileName);
}
store(outStr, "# Written by FileProperty.save() at " + new Date());
} /** 关闭流 */
public void close() {
try {
if (inStr != null) {
inStr.close();
}
if (outStr != null) {
outStr.close();
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}把信息写入SQLconnection.properties文件,可以用下面的代码得到:
FileProperty sqlProperty=null; try { sqlProperty = new FileProperty("SQLconnection.properties"); } catch (IOException ex) { ex.printStackTrace(); } String user=sqlProperty.getProperty("user"); String password=sqlProperty.getProperty("password"); sqlProperty.close();完整的信息可以访问
http://www.blogcn.com/user41/blog_of_phil/index.html