我的测试

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;


public class TestDB
{
private String dbConnection;

private String userName;

private String password;

private String executeSql;

private Connection con = null;

private PreparedStatement state = null;

private ResultSet resultSet = null;

public Connection getCon() {
return con;
}

public void setCon(Connection con) {
this.con = con;
}

/**
* @param args
*/
public void doExecute(String[] args) {
BufferedInputStream inputStream = null;
try {
inputStream = new BufferedInputStream(new FileInputStream(new File(
"dbConfig.properties")));

Properties dbConfigProperties = new Properties();
dbConfigProperties.load(inputStream);

setDBConfig(dbConfigProperties);

querySQL(dbConfigProperties.getProperty("querysql"));



} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

public void setDBConfig(Properties dbProperties)
{
this.dbConnection = dbProperties.getProperty("dburl");
this.userName = dbProperties.getProperty("username");
this.password = dbProperties.getProperty("password");
}

public void querySQL(String querySQL)
{
try {
con = DriverManager.getConnection(this.dbConnection, userName, password);
state = con.prepareStatement(querySQL);
// PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES
//                    SET SALARY = ? WHERE ID = ?");
//pstmt.setBigDecimal(1, 153833.00)
//pstmt.setInt(2, 110592)

resultSet = state.executeQuery();
while (resultSet.next())
{
resultSet.getInt(columnName)
}

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public String getDbConnection() {
return dbConnection;
}

public void setDbConnection(String dbConnection) {
this.dbConnection = dbConnection;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

}

猜你喜欢

转载自fcxx182.iteye.com/blog/2191625