作者:敖士伟
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>
2 MyEclipse
我用的ALL IN ONE安全版myeclipse-8.5.0-win32.exe。安全好就可以了。
3 配置Resin与MyEclipse整合
配置好了就可以MyEclipse中启动Resin了
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项目
4.3添加JDBC驱动引用
先在项目上右击,然后
选择“Add External Archives”才会所JDBC驱动发布到应用目录中。
4.4添加jsp文件
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 发布项目
完