Java connect to oracle

Java connect to oracle[@more@]

Fun : FB_DataSource:

-------------------------------

package rpt_finalbill;

import java.sql.*;

import oracle.jdbc.pool.*;

public class FB_DataSource{

private static OracleDataSource ds;
/*
private static final String DRIVER_TYPE = "thin";
private static final String SERVER_NAME = "172.20.105.101";
private static final int PORT_NUMBER = 31522;
private static final String DATABASE_NAME = "bill_bi";
*/
private static final String USER = "retbatch";
private static final String PASSWORD = "retbatch";

/*//Prod//private static final String CONNECTION_URL =
"jdbc:oracle:thin:@(DESCRIPTION ="
+"(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = billrpt1)(PORT = 31523))) (CONNECT_DATA = (SERVICE_NAME = gnvprd) ) "
+")";*/
private static final String CONNECTION_URL =
"jdbc:oracle:thin:@(DESCRIPTION ="
+"(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = 175.30.100.58) (PORT = 1523))) (CONNECT_DATA = (SERVICE_NAME = bill_bi) ) "
+")";
public FB_DataSource () throws SQLException
{
ds = new OracleDataSource();
/*
ds.setDriverType(DRIVER_TYPE);
ds.setServerName(SERVER_NAME);
ds.setPortNumber(PORT_NUMBER);
ds.setDatabaseName(DATABASE_NAME);
*/
ds.setURL(CONNECTION_URL);
ds.setUser(USER);
ds.setPassword(PASSWORD);

}
/*
public int getPortNumber()
{
return PORT_NUMBER;
}

public String getServerName()
{
return SERVER_NAME;
}

public String getDatabaseName()
{
return DATABASE_NAME;
}
public String getDriverType()
{
return DRIVER_TYPE;
}
*/
public String getUserName()
{
return USER;
}

public Connection getConnection()
throws SQLException
{
return ds.getConnection();
}

public String getConnectionDetails()
{
StringBuffer sbuf = new StringBuffer(200);

sbuf.append("Class : ").append(this.getClass().getName())
.append("nURL: ").append(CONNECTION_URL);
/*
.append("nServer name: ").append(getServerName())
.append("nPort: ").append(String.valueOf(getPortNumber()))
.append("nDatabase name: ").append(getDatabaseName())
.append("nUser name: ").append(getUserName())
;
*/
return sbuf.toString();
}

public static void main(String args[]) throws SQLException
{
FB_DataSource dataSource = new FB_DataSource();
System.out.println(dataSource.getConnectionDetails());
dataSource.getConnection();
}

}

===================

public void preLoad(HttpServletRequest request, HttpServletResponse response,Hashtable requestValue,String userName)throws Exception{
BILLConnectionPool ds = null;
Connection conn = null;
String uploadMessage = null;
String uploadStatus = null;
String uploadFile = null;
try{
ds = new BILLConnectionPool();
conn = ds.getBill04Connection();
int total = 0;
String account_num = null;
String account_name = null;
boolean flag = false;
String mobile = null;
String psid = null;
String cost_centre = null;
String plan = null;
String ref_name = null;
String total_charge = null;
String invoice_date = null;
String invoice_num = null;

ArrayList a = (ArrayList)requestValue.get("uploadFile");
String ofileName =(String)requestValue.get("fileName");
request.setAttribute("uploadFile",ofileName);
String fileName = ofileName.substring(ofileName.lastIndexOf("")+1);
//System.out.println("fileName: "+ fileName);

String sql1 = "DELETE FROM GENEVA_ADMIN.SMC_COST_CENTRE_STATEMENT_RPT";
PreparedStatement pstmt = conn.prepareStatement(sql1);
//pstmt.execute();
//pstmt.close();

String sql3 = "COMMIT";
PreparedStatement pstmt3 = conn.prepareStatement(sql3);
//pstmt3.execute();

String sql2 = "INSERT INTO GENEVA_ADMIN.SMC_COST_CENTRE_STATEMENT_RPT(ACCOUNT_NUM,ACCOUNT_NAME,MOBILE,PSID,COST_CENTRE,PLAN,REF_NAME,TOTAL_CHARGE,INVOiCE_NUM,INVOICE_DATE,CREATED_BY)"+
" VALUES( ?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement pstmt2 = conn.prepareStatement(sql2);


for(int i=0;i String readLine = (String)a.get(i);
if(readLine.length() == 0){
continue;
}
String temp[] = readLine.split(",");

if(temp[0].equals("Account No.:")){
account_num = temp[1];
continue;
}
else if(temp[0].equals("Name:")){
account_name = temp[1];
continue;
}
else if(temp[0].equals("Invoice no.:")){
invoice_num = temp[1];
invoice_date = temp[1].substring(0,8);
boolean checkDateFlag = false;
checkDateFlag = checkDate(invoice_date);

String account_num_check = temp[1].substring(temp[1].length()-8);
if(!account_num.equals(account_num_check)){
uploadStatus = "False";
uploadMessage = "Error: Account No.("+account_num+") does not match the last eight digits of Invoice No.("+account_num_check+")";
break;
}
else if(! checkDateFlag){
uploadStatus = "False";
uploadMessage = "Error: Wrong format of Invoice Date("+invoice_date+")";
break;
}
else{
pstmt.execute();
pstmt.close();
pstmt3.execute();
continue;
}
}
else if(temp[0].equals("Mobile")){
flag = true;
continue;
}
else if(flag && (temp[0] != null && !"".equals(temp[0]))){
mobile = temp[0];
psid = temp[1];
cost_centre = temp[2];
plan = temp[3];
ref_name = temp[4];
total_charge = temp[5];

pstmt2.setString(1,account_num);
pstmt2.setString(2,account_name);
pstmt2.setString(3,mobile);
pstmt2.setString(4,psid);
pstmt2.setString(5,cost_centre);
pstmt2.setString(6,plan);
pstmt2.setString(7,ref_name);
pstmt2.setString(8,total_charge);
pstmt2.setString(9,invoice_num);
pstmt2.setString(10,invoice_date);
pstmt2.setString(11,userName);
pstmt2.execute();

total = total +1;
}
}
pstmt2.close();
pstmt3.execute();
pstmt3.close();
if(!"False".equals(uploadStatus)){
uploadStatus = "True";
uploadMessage = "'"+fileName+"' is uploaded successfully.
"+total+" records are uploaded.";
}
System.out.println("Total: "+total);
request.setAttribute("uploadMessage",uploadMessage);
request.setAttribute("uploadStatus",uploadStatus);
request.getRequestDispatcher("SCB/Cost_centre_statement.jsp").forward(request,response);
return;
}catch (Exception e){
System.out.print("Error: "+e.toString());
//throw new RuntimeException(e);
request.setAttribute("uploadMessage","Error: "+e.toString());
request.setAttribute("uploadStatus","False");
request.getRequestDispatcher("SCB/Cost_centre_statement.jsp").forward(request,response);
return;
}
finally{
conn.close();
}
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/640706/viewspace-1047869/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/640706/viewspace-1047869/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值