真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

一個簡單的JDBC連接程序

package com;

創(chuàng)新互聯(lián)是一家從事企業(yè)網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計、成都做網(wǎng)站、行業(yè)門戶網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計制作的專業(yè)網(wǎng)絡(luò)公司,擁有經(jīng)驗豐富的網(wǎng)站建設(shè)工程師和網(wǎng)頁設(shè)計人員,具備各種規(guī)模與類型網(wǎng)站建設(shè)的實力,在網(wǎng)站建設(shè)領(lǐng)域樹立了自己獨特的設(shè)計風格。自公司成立以來曾獨立設(shè)計制作的站點超過千家。

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

public class NavalMgmtDAO {

public static void main(String[] args) {

NavalMgmtDAO navalMgmtDAO=new NavalMgmtDAO();

double sal=navalMgmtDAO.getOfficersTotalSalOnBaseCamp(38);

System.out.println(sal);

}

public int addNavalOfficer(NavalOfficer navalOfficer)

{

int no=navalOfficer.getOfficerNo();

String name=navalOfficer.getOfficerName();

String rank=navalOfficer.getOfficerRank();

double sal=navalOfficer.getOfficerSal();

int campid=navalOfficer.getBaseCampId();

Connection connection = null;

int status = 0;

DBConnectionHelper helper = new DBConnectionHelper();

connection = helper.getOracleConnection();

Statement statement = null;

try {

connection.setAutoCommit(false);

statement = connection.createStatement();

String sql = "INSERT INTO TBL_Officer_1273752 values (" +no+",'"+name+"','"+rank+"',"+sal+","+campid+")";

status = statement.executeUpdate(sql);

connection.commit();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

finally {

try {

if (statement != null)

statement.close();

// System.out.println("STATEMENT SUCCESSFULLY CLOSED");

} catch (SQLException se) {

se.printStackTrace();

}// do nothing

try {

if (connection != null)

connection.close();

// System.out.println("CONNECTION SUCCESSFULLY CLOSED");

} catch (SQLException se) {

se.printStackTrace();

}// end finally try

}// end try

if (status == 1) {

System.out.println("Data inserted successfully");

}else{

System.out.println("Connection error");

}

return status;

}

public int addBaseCamp(BaseCamp baseCamp)

{

int id=baseCamp.getBaseCampId();

String name=baseCamp.getBaseCampName();

int loc=baseCamp.getBaseCampLoc();

Connection connection = null;

int status = 0;

DBConnectionHelper helper = new DBConnectionHelper();

connection = helper.getOracleConnection();

Statement statement = null;

try {

connection.setAutoCommit(false);

statement = connection.createStatement();

String sql = "INSERT INTO TBL_Base_Camp_1273752 values (" +id+",'"+name+"','"+loc+"')";

status = statement.executeUpdate(sql);

connection.commit();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

finally {

try {

if (statement != null)

statement.close();

// System.out.println("STATEMENT SUCCESSFULLY CLOSED");

} catch (SQLException se) {

se.printStackTrace();

}// do nothing

try {

if (connection != null)

connection.close();

// System.out.println("CONNECTION SUCCESSFULLY CLOSED");

} catch (SQLException se) {

se.printStackTrace();

}// end finally try

}// end try

if (status == 1) {

System.out.println("Data inserted successfully");

}else{

System.out.println("Connection error");

}

return status;

}

public ArrayList  getOfficersNameSortedBySal()

{

ArrayList arrayList=new ArrayList();

Connection connection = null;

DBConnectionHelper helper = new DBConnectionHelper();

connection = helper.getOracleConnection();

Statement statement = null;

ResultSet resultSet = null;

try {

statement = connection.createStatement();

String sql = "select officer_name from tbl_officer_1273752 order by officer_sal";

resultSet = statement.executeQuery(sql);

while (resultSet.next()) {

String name = resultSet.getString(1);

arrayList.add(name);

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {

try {

if (statement != null)

statement.close();

} catch (SQLException se) {

}// do nothing

try {

if (connection != null)

connection.close();

} catch (SQLException se) {

se.printStackTrace();

}// end finally try

if (resultSet != null) {

try {

resultSet.close();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}// end try

return arrayList;

}

public ArrayList  getOfficersNameForBaseCampLoc(String baseCampLoc)

{

ArrayList arrayList=new ArrayList();

Connection connection = null;

DBConnectionHelper helper = new DBConnectionHelper();

connection = helper.getOracleConnection();

Statement statement = null;

ResultSet resultSet = null;

try {

statement = connection.createStatement();

String sql = "select officer_name from tbl_officer_1273752 where base_camp_id in (select base_camp_id from tbl_base_camp_1273752 where base_camp_loc='"+baseCampLoc+"')";

resultSet = statement.executeQuery(sql);

while (resultSet.next()) {

String name = resultSet.getString(1);

arrayList.add(name);

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {

try {

if (statement != null)

statement.close();

} catch (SQLException se) {

}// do nothing

try {

if (connection != null)

connection.close();

} catch (SQLException se) {

se.printStackTrace();

}// end finally try

if (resultSet != null) {

try {

resultSet.close();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}// end try

return arrayList;

}

public double getOfficersTotalSalOnBaseCamp(int baseCampId)

{

double sal=0;

Connection connection = null;

DBConnectionHelper helper = new DBConnectionHelper();

connection = helper.getOracleConnection();

Statement statement = null;

ResultSet resultSet = null;

try {

statement = connection.createStatement();

String sql = "select sum(officer_sal) from tbl_officer_1273752 where base_camp_id="+baseCampId+"";

resultSet = statement.executeQuery(sql);

while (resultSet.next()) {

sal= resultSet.getDouble(1);

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {

try {

if (statement != null)

statement.close();

} catch (SQLException se) {

}// do nothing

try {

if (connection != null)

connection.close();

} catch (SQLException se) {

se.printStackTrace();

}// end finally try

if (resultSet != null) {

try {

resultSet.close();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}// end try

return sal;

}

}


分享題目:一個簡單的JDBC連接程序
當前URL:http://weahome.cn/article/jjsgjo.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部