低
低调一贱男
Unregistered / Unconfirmed
GUEST, unregistred user!
我根据网上的资料将conf/server.xml修改如下:
<!-- Tomcat Root Context -->
<Context path=""do
cBase="ROOT" debug="0" reloadable="true">
<Resource name="jdbc/SqlServer" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/SqlServer">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://yt3/EEEE:1433;databaseName=room</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value>966123</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
</Context>
始终配置不成功,各位如果配置过的,麻烦告诉我啊,我以前用websphere的,现在的公司买不起,只有用tomcat了.
我用如下代码测试的
package gameserver;
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
public class DBTest {
String foo = "Not Connected";
int bar = -1;
public void init() {
try{
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");
DataSource ds =(DataSource)ctx.lookup( "java:comp/env/jdbc/SqlServer");
if (ds != null) {
Connection conn = ds.getConnection();
if(conn != null) {
foo = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
ResultSet rst =stmt.executeQuery( "select * from five");
if(rst.next()) {
foo=rst.getString(2);
bar=rst.getInt(3);
}
conn.close();
}
}
}catch(Exception e) {
e.printStackTrace();
}
}
public String getFoo() { return foo;
}
public int getBar() { return bar;}
}
<!-- Tomcat Root Context -->
<Context path=""do
cBase="ROOT" debug="0" reloadable="true">
<Resource name="jdbc/SqlServer" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/SqlServer">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://yt3/EEEE:1433;databaseName=room</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value>966123</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
</Context>
始终配置不成功,各位如果配置过的,麻烦告诉我啊,我以前用websphere的,现在的公司买不起,只有用tomcat了.
我用如下代码测试的
package gameserver;
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
public class DBTest {
String foo = "Not Connected";
int bar = -1;
public void init() {
try{
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");
DataSource ds =(DataSource)ctx.lookup( "java:comp/env/jdbc/SqlServer");
if (ds != null) {
Connection conn = ds.getConnection();
if(conn != null) {
foo = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
ResultSet rst =stmt.executeQuery( "select * from five");
if(rst.next()) {
foo=rst.getString(2);
bar=rst.getInt(3);
}
conn.close();
}
}
}catch(Exception e) {
e.printStackTrace();
}
}
public String getFoo() { return foo;
}
public int getBar() { return bar;}
}