<datasources>
<local-tx-datasource>
<jndi-name>MSSQLDS</jndi-name>
<connection-url>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=JBossDB</connection-url>
<driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
<user-name>sa</user-name>
<password>5207865</password>
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
--> <!-- sql to call on an existing pooled connection when it is obtained from pool
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
--> </local-tx-datasource></datasources>
用上面这个试一下 你自己把相应的地方该一下
如果不行 你告诉我 你的JBOSS的版本
<local-tx-datasource>
<jndi-name>MSSQLDS</jndi-name>
<connection-url>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=JBossDB</connection-url>
<driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
<user-name>sa</user-name>
<password>5207865</password>
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
--> <!-- sql to call on an existing pooled connection when it is obtained from pool
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
--> </local-tx-datasource></datasources>
用上面这个试一下 你自己把相应的地方该一下
如果不行 你告诉我 你的JBOSS的版本
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;public class test1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String s="";
Properties env = new Properties();
env.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
env.setProperty("java.naming.provider.url", "jnp://localhost:1099");
env.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
try {
InitialContext ctx=new InitialContext(env);
DataSource ds=(DataSource)ctx.lookup("java:/MSSQLDS");
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
try{
con=ds.getConnection();
stmt=con.createStatement();
rs=stmt.executeQuery("select * from user");
while(rs.next()){
s+="Username:"+rs.getString("username")+" password:"+rs.getString("pwd")+"\n";
}
}catch(Exception e){
e.printStackTrace();
}finally{
try {
rs.close();
stmt.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
} catch (NamingException e) {
e.printStackTrace();
}
}}
还是说数据库not bound!
能不能说的详细点。万分感谢
local是本地连接,而你的测试是remote.
因此不行...