程序没有找到你配的sqlserver,在weblogic中配的有问题,自己在看看
解决方案 »
- js list 去掉重复的方法
- 工程中插入图片问题!!!
- Hibernate的getHibernateTemplate().delete(Object object)出现类型转换异常
- SpringAOP能解决什么实际问题(提供链接者也有分)?
- 求助各路大神,不同功能不同服务器处理,寻求解决方案,急!!!!!
- 有个关于fileupload的问题想问下大家
- 初学者:为什么我做的用jdbc连接sqlserver总是报加载驱动程序错误
- 在上海,熟悉struts和hibernate的朋友请进
- 这个问题怎么解决?
- jb7怎样解密?
- 急,急,高分求购,请问在jboss里面怎么建立sql server2000 数据源?
- FETCH_REVERSE 和 TYPE_SCROLL_SENSITIVE 的区别
正确的过程是这样的:
先设置连接池:比如SQLServerPool(jndi name),然后设置好连接池的连接数据库的信息,比如用户名,密码。
然后,配置数据源:SQLServerDS(jndi name),并指向上面的SQLServerPool.
程序里这样获得连接: Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");//t3___协议代表
try
{
Context ctx = new InitialContext(ht);
DataSource ds = (DataSource)ctx.lookup("SQLServerDS");
Connection con = ds.getConnection();
Statement st = con.createStatement();
ResultSet res = st.executeQuery("select * from employees");
String line = "";
while (res.next())
line = line + res.getString("notes")+"\n";
jTextArea1.setText(line);
con.close();
}
catch (Exception ex)
{
jTextArea1.setText("error : "+ex.getMessage());
}
真的吗????
真的好了为什么会找不到 ?!
还是你的配置问题
具体配置贴出来 ------------------------------------------------------
我们还年轻牛奶会有的奶牛也会有的
可天天在 csdn 混这些会有吗 ??
可能weblogic自带的sqlserver的驱动程序有问题。
谢谢大家!!!
可能weblogic自带的sqlserver的驱动程序有问题。
谢谢大家!!!
import java.util.*;
import javax.naming.*;
import javax.sql.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class DBConnection {
public DBConnection() {
//
init();
} /**
* 记录查询语句
*/
public static String sqlStatement;
private static Statement statement;
private static Connection connection;
private static String driverName =
"com.microsoft.jdbc.sqlserver.SQLServerDriver";
private static String jdbcURL =
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=storage";
private static String userName = "sa";
private static String password = "123456";
private static Context ctx = null;
private static boolean Debug_Local = true;
private static String uRL = "t3://localhost:7001"; //t3://mysoftxmen:7001
private static String dataSource = "Storagetxds"; //DataSource
/**
* 返回连接
* @return 返回当前连接
*/
static public void init() {
try {
//setConnection(driverName, jdbcURL, userName, password); if (Debug_Local) {
setDataSource("t3://localhost:7001", "Storagetxds");
}
else {
setDataSource(uRL, dataSource);
/* setConnection(driverName,jdbcURL,userName,password);*/
// //setConnection("DriverName", "jdbcURL", "userName", "password");
}
}
catch (Exception Ex) {
Ex.printStackTrace();
}
} static public Connection getConnection() {
init();
return connection;
} /**
* Access method for the sqlStatement property.
*
* @return the current value of the sqlStatement property
*/
static public String getSqlStatement() {
return sqlStatement;
} /**
* Sets the value of the sqlStatement property.
*
* @param aSqlStatement the new value of the sqlStatement property
*/
static public void setSqlStatement(String aSqlStatement) {
sqlStatement = aSqlStatement;
} /**
* 设置通过驱动程序库方式的数据库连接
*
* @param driverName
* @param jdbcURL
* @param username
* @param passwd
* @throws java.lang.Exception
* @throws new97.Common.YhException
* @deprecated 单线程方式,不推荐使用
*/
static public void setConnection(String driverName, String jdbcURL,
String username, String passwd) throws
Exception {
Class.forName(driverName);
connection = DriverManager.getConnection(jdbcURL, username, passwd);
statement = connection.createStatement();
connection.setAutoCommit(false);
} /**
* 设置通过DataSource方式的数据库连接
*
* @param aHostName
* @param aDataSourceName
* @throws java.lang.Exception
* @throws new97.Common.YhException
*/
static public void setDataSource(String aHostName, String aDataSourceName) throws
Exception {
String url = aHostName; //mysoftxmen" t3://mysoftxmen:7001"
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS,
password == null ? "" : password);
} }
catch (Exception e) {
throw e;
} try {
ctx = new InitialContext(properties);
//java:comp/env/jdbc/DataSource
DataSource ds = (DataSource) ctx.lookup(aDataSourceName); //DataSource
//DataSource ds = (DataSource)LookupObj.getRemoteObj(aHostName,aDataSourceName,DataSource.class);
connection = ds.getConnection();
// statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
connection.setAutoCommit(false);
}
catch (Exception e) {
e.printStackTrace();
}
} static public ResultSet executeQuery(String aQuerySQL) throws Exception {
try {
return statement.executeQuery(aQuerySQL);
}
catch (Exception e) {
String errArg[] = new String[] {
aQuerySQL};
throw e;
}
} static public void executeNonQuery(String aSQLStatement) throws SQLException {
try {
statement.execute(aSQLStatement);
}
catch (SQLException e) {
throw e;
} } static public void beginTran() throws Exception { } /**
* 错误时抛出异常
*
*
*/
static public void commit() throws Exception {
try {
connection.commit();
}
catch (Exception e) {
throw e;
}
} /**
* 错误时抛出异常"
*
*
*/
static public void rollback() throws Exception {
try {
connection.rollback();
}
catch (Exception e) {
throw e;
}
} /**
* 执行带参数的语句,执行前先用
*/
static public void executeNonQuery(String aParam[]) throws Exception {
PreparedStatement DynStm;
try {
DynStm = connection.prepareStatement(sqlStatement);
if (aParam != null) {
for (int i = 0; i < aParam.length; i++) {
DynStm.setString(i + 1, aParam[i]);
}
}
DynStm.execute();
DynStm.close();
}
catch (Exception e) {
throw e;
}
} protected void finalize() throws Exception {
try {
this.statement.close();
this.connection.close();
}
catch (Exception e) {
throw e;
}
} /**
* 释放连接
* @
*/
public void close() throws Exception {
try {
if (this.statement != null) {
this.statement.close();
}
if (this.connection != null) {
this.connection.close();
}
}
catch (Exception e) {
throw e;
}
}}