java配置sql_java 开发+运行环境配置+连接 sql 2008

作者:敖士伟

1 Resin

1.1将resin-pro-4.0.7.zip解压:D:/servers

1.2 设置JAVA_HOME 如:D:/Sun/SDK/jdk

1.3 设置RESIN_HOME 如:D:/servers/resin-pro-4.0.7

1.4 启动Resin

D:/servers/resin-pro-4.0.7/lib>java -jar resin.jar

Resin requires a command:

console - start Resin in console mode

status - watchdog status

start - start a Resin server

stop - stop a Resin server

restart - restart a Resin server

kill - force a kill of a Resin server

shutdown - shutdown the watchdog

D:/servers/resin-pro-4.0.7/lib>java -jar resin.jar start

Resin/4.0.7 launching watchdog at 127.0.0.1:6600

Resin/4.0.7 started -server '' for watchdog at 127.0.0.1:6600

D:/servers/resin-pro-4.0.7/lib>java -jar resin.jar stop

Resin/4.0.7 stopped -server '' for watchdog at 127.0.0.1:6600

D:/servers/resin-pro-4.0.7/lib>

0818b9ca8b590ca3270a3433284dd417.png

2 MyEclipse

我用的ALL IN ONE安全版myeclipse-8.5.0-win32.exe。安全好就可以了。

3 配置Resin与MyEclipse整合

0818b9ca8b590ca3270a3433284dd417.png

0818b9ca8b590ca3270a3433284dd417.png

配置好了就可以MyEclipse中启动Resin了

0818b9ca8b590ca3270a3433284dd417.png

4 连接到Sql Server 2008

4.1 JDBC驱动

JDBC驱动用的Sql Server 2008官方驱动: SQL Server JDBC Driver 3.0

需要注意的是:现在JRE一般是1.6,所以,我们选用的是sqljdbc4.jar

4.2 创建Web项目

0818b9ca8b590ca3270a3433284dd417.png

4.3添加JDBC驱动引用

先在项目上右击,然后

0818b9ca8b590ca3270a3433284dd417.png

选择“Add External Archives”才会所JDBC驱动发布到应用目录中。

4.4添加jsp文件

0818b9ca8b590ca3270a3433284dd417.png

4.5写代码

test

// Create a variable for the connection string.

String connectionUrl = "jdbc:sqlserver://192.168.0.201:2008;" +

"databaseName=testA;user=sa;password=ikmbikmb;";

// Declare the JDBC objects.

Connection con = null;

Statement stmt = null;

ResultSet rs = null;

try {

// Establish the connection.

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

con = DriverManager.getConnection(connectionUrl);

// Create and execute an SQL statement that returns a

// set of data and then display it.

String SQL = "SELECT top 100 * FROM Table_1;";

stmt = con.createStatement();

rs = stmt.executeQuery(SQL);

System.out.println("a");

while (rs.next()) {

out.println(rs.getString("val")+"
");

}

}

// Handle any errors that may have occurred.

catch (Exception e) {

e.printStackTrace();

}

finally {

if (rs != null) try { rs.close(); } catch(Exception e) {}

if (stmt != null) try { stmt.close(); } catch(Exception e) {}

if (con != null) try { con.close(); } catch(Exception e) {}

}

%>

5 发布项目

0818b9ca8b590ca3270a3433284dd417.png

0818b9ca8b590ca3270a3433284dd417.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值