`
leanore
  • 浏览: 5600 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Windchill中使用JDBC查询

    博客分类:
  • java
阅读更多
需要注意,wtconnection不能关闭
package ext.leanore.util;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import wt.auth.SimpleAuthenticator;
import wt.method.MethodContext;
import wt.method.MethodServerException;
import wt.method.RemoteMethodServer;
import wt.pom.DataServicesRegistry;
import wt.pom.UnsupportedPDSException;
import wt.pom.WTConnection;

/**
 * @author leanore
 */
public class DBOperator {

	/**
	 * @param sql
	 * @param parameters
	 * @return
	 */
	public static Vector<?> doQuery(String sql, String[] parameters) {
		Vector<?> vec = new Vector<Object>();
		WTConnection wtconnection = null;
		PreparedStatement pstmt = null;
		ResultSet result;

		try {
			MethodContext methodcontext = getMethodContext();
			wtconnection = (WTConnection) methodcontext.getConnection();
			pstmt = wtconnection.prepareStatement(sql);
			if (parameters != null) {
				for (int j = 1; j <= parameters.length; j++) {
					 pstmt.setString(j, parameters[j - 1]);
				}
			}
			result = pstmt.executeQuery();
			vec = getResult(result);
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			if (pstmt != null) {
				try {
					pstmt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		return vec;

	}

	private static Vector<?> getResult(ResultSet result) {
		//对查询结果进行封装
		return new Vector<Object>();
	}

	/**
	 ***************************************
	 * ClassName:DBOperator
	 * @TODO: <P></P>
	 *
	 * @author   leanore
	 * @since    leanore -Ver 1.1
	 * @Date  2011-7-1
	 * @return
	 * @throws UnsupportedPDSException
	 * @throws UnknownHostException
	 ***************************************
	 */
	public static MethodContext getMethodContext()
			throws UnsupportedPDSException, UnknownHostException {
		MethodContext methodcontext;
		try {
			methodcontext = MethodContext.getContext();
		} catch (MethodServerException methodserverexception) {
			RemoteMethodServer.ServerFlag = true;
			InetAddress inetaddress = InetAddress.getLocalHost();
			String s = inetaddress.getHostName();
			if (s == null)
				s = inetaddress.getHostAddress();
			SimpleAuthenticator simpleauthenticator = new SimpleAuthenticator();
			methodcontext = new MethodContext(s, simpleauthenticator);
			methodcontext.setThread(Thread.currentThread());
			wt.pds.PDSIfc pdsifc = DataServicesRegistry.getDefault().getPdsFor("DEFAULT");
		}
		return methodcontext;
	}
}
分享到:
评论

相关推荐

    Windchill+spring+mybatis

    为了更好地利用Windchill的功能,并将其与其他系统(如Spring框架和MyBatis等)进行有效集成,本文将详细介绍如何在Windchill环境中配置并使用Spring+MyBatis框架。 #### 二、Spring+MyBatis简介 Spring框架是一种...

    Windchill二次开发数据库连接及操作的两种方式代码

    本文将详细介绍两种在Windchill二次开发中进行数据库连接和操作的方法:一是通过Windchill自身的API,二是使用JDBC连接Oracle数据库。 首先,让我们探讨第一种方法——使用Windchill API进行数据库操作。Windchill...

    windchill11.0开发API

    7. **Data Access and Persistence**:通过ODBC/JDBC和Windchill Repository API,开发者可以访问和操作Windchill数据库中的数据。 学习和使用Windchill 11.0 API时,开发者需要注意以下几点: - **了解基础概念**...

    windchill10.0&11;.0api_chm版

    开发者可以通过它来学习如何在程序中调用WindChill的接口,实现对产品数据的创建、修改、查询等操作。 - `windchill10.0.chm`:可能包含了WindChill 10.0的其他辅助信息或者特定模块的API,比如工作流、配置管理等...

    Windchill development with JPQL

    接下来,将详细介绍JPQL在Windchill开发中的应用、配置方法以及具体的查询操作。 首先,JPQL是为了克服Windchill开发中的常见困扰而诞生的。传统的Windchill数据库操作主要依赖于JDBC、QuerySpec接口和Info*Engine...

    Windchill102M020_安装配置(Windows篇).zip

    1. **创建Windchill站点**: 在WebSphere管理控制台中创建新的WebSphere应用程序服务器和部署Windchill应用。 2. **配置数据源**: 设置JDBC数据源,连接到前面配置的数据库。 3. **配置邮件服务器**: 如果需要邮件...

    Windchill-development-using-JPQL-v1.2.1

    总结来说,Windchill开发中使用JPQL v1.2.1可以显著提升复杂查询的可读性和效率,减少了O/R转换的负担。通过PQL和JPQL,开发者可以更加灵活地处理业务对象和数据库表之间的交互,从而提高开发效率和代码质量。

    JPQL package

    在Windchill开发中,使用JPQL可以更高效地查询和操作存储在Windchill数据库中的对象,如产品结构、工作流程状态等。通过集成JPA和JPQL,开发者可以构建出更强大、更易维护的数据访问层。 7. **codebase与lib文件夹...

    springMVC配置

    在Spring MVC中,这些信息会被Spring的JDBC或DataSource类使用,以便进行数据操作。 4. `oscache.tld`:TLD(Tag Library Descriptor)文件是用于定义自定义标签库的描述文件,这里可能是OSCache提供的JSP标签库,...

    spring applicationContext 配置文件

    -- ptc windchill的數據庫 --&gt; &lt;property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/&gt; &lt;property name="jdbcUrl" value="jdbc:oracle:thin:@10.142.252.132:1521:mesdev"/&gt; ...

Global site tag (gtag.js) - Google Analytics