高人给解释一下,明天结账,不够再开贴。

dlkfth 2004-01-07 03:48:01
package com.landsea.myservlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

import java.sql.*;
import sun.jdbc.rowset.*;
import com.landsea.sendclass.SendClass;
import com.landsea.cachedrowsetwrapper.*;
import java.net.*;
import com.landsea.myexception.*;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class MyServlet extends HttpServlet {
//private static final String CONTENT_TYPE = "text/html; charset=GBK";
private static final String CONTENT_TYPE = "application/octet-stream";
//Initialize global variables
/******************初始化数据库的驱动程序********************/
static
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
System.out.println("success for name");
}
catch(ClassNotFoundException cnfe)
{
System.err.println(cnfe.getMessage());
cnfe.printStackTrace();
}
}
/******************初始化数据库的驱动程序********************/

public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
///**********************************

/************************************************************/

System.out.println("成功调用Servlet");
String inLawOrNot = null;
inLawOrNot = request.getParameter("DataQuery");
System.out.println("调用参数是:" + inLawOrNot);
if(inLawOrNot == null) return;
try
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
System.out.println("success for name");
}
catch(ClassNotFoundException cnfe)
{
System.err.println(cnfe.getMessage());
cnfe.printStackTrace();
}

Connection dbcon = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://192.168.102.81:1433;DatabaseName=CBJYW;user=sa;Password=");
System.out.println("连接数据库成功");

ObjectInputStream ois = new ObjectInputStream(request.getInputStream());
SendClass sendClass = (SendClass)ois.readObject();
ois.close();

//***********************************
System.out.println(sendClass.getQueryStatement());

System.out.println("成功接受数据对象");

Statement sqlStatement = dbcon.createStatement();
String dbsql = sendClass.getQueryStatement();



ResultSet dbResultSet = sqlStatement.executeQuery(dbsql);
CachedRowSet crs = new CachedRowSet();//?
crs.populate(dbResultSet);

// 关闭一些使用完的对象
dbResultSet.close();
sqlStatement.close();
dbcon.close();

//定义CachedRowSetWrapper类来传送给applet端
CachedWrapper cw = new CachedWrapper();
SetCachedWrapper(cw,crs);
crs.close();

ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream());
oos.writeObject(cw);
oos.close();

System.out.println("成功传送对象给Applet");


}
catch(MyException me)
{
System.out.println(me.getMessage());
}
catch(SQLException sqle)
{
System.out.println("success fail");
System.out.println(sqle.getMessage());
sqle.printStackTrace();
}
catch(ClassNotFoundException cnfe)
{
System.err.println(cnfe.getMessage());
cnfe.printStackTrace();
}

}

//必须保证CachedRowSet 传入前要保证不是空
public void SetCachedWrapper(CachedWrapper cw,CachedRowSet crs) throws SQLException{
try{
while(crs.next()){
cw.setAbsoluteDepth(crs.getString("绝对深度"));
cw.setLongitude(crs.getString("经度"));
cw.setLatitude(crs.getString("纬度"));
cw.setWindDirect(crs.getString("风向"));
cw.setHeading(crs.getString("船首风向"));
cw.setRelativeWaterVelocity(crs.getString("相对水速度"));
cw.setRelativeGroundVelocity(crs.getString("相对地速度"));
cw.setResetCourse(crs.getString("复位里程"));
cw.setTotalCourse( crs.getString("总里程"));
cw.setAutoPilotUnits(crs.getString("自动舵单位"));
}
}
catch(SQLException sqle)
{
System.err.println(sqle.getMessage());
sqle.printStackTrace();
throw sqle;
}
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}
...全文
69 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
delphi57 2004-01-12
  • 打赏
  • 举报
回复
up
xjhwq 2004-01-12
  • 打赏
  • 举报
回复
up
yekai012 2004-01-12
  • 打赏
  • 举报
回复
up..............
longyifei 2004-01-11
  • 打赏
  • 举报
回复
up
pleonheart 2004-01-10
  • 打赏
  • 举报
回复
up,接分
xjhwq 2004-01-10
  • 打赏
  • 举报
回复
up
studyking 2004-01-09
  • 打赏
  • 举报
回复
com.microsoft.jdbc.sqlserver.SQLServerDriver
该怎么用。要写眼光驱动程序的。class
我用的是数据源的sun.jdbc.odbc.JdbcOdbcDriver十分不爽
我想知道.class文件怎么写
Shrewdcat 2004-01-09
  • 打赏
  • 举报
回复
2、public void doGet(HttpServletRequest request, HttpServletResponse response) 详细解释一下好吗?


HttpServlet中有doGet,doPost and Service 三个函数,service 包涵了doGet and doPost的功能,一般来说,可以不实现出doGet or doPost,只要实现出Service函数就足够了。除非在严格区分get and post 时。
freejames 2004-01-09
  • 打赏
  • 举报
回复
public void doGet(HttpServletRequest request, HttpServletResponse response)
好像 HttpServlet 中定义的一个接口, 必须要在继承中的类中实现, 具体在什么时候实现,可以在HttpServlet中查看
freejames 2004-01-09
  • 打赏
  • 举报
回复
1、com.microsoft.jdbc.sqlserver.SQLServerDriver
你打开对应的SqlServer jdbc驱动程序的jar文件,可以找到对应目录中的class文件。
import的用处相当于指定对应的jar文件中的目录结构,由于使用了全部路径应此可以不用import了。 相应的,你也可以直接在java中不用Import直接在类的前面加入对应的路径。
2、Statement是jdbc的一个类,相当于一个数据连接。
filippo1980 2004-01-09
  • 打赏
  • 举报
回复
up
dlkfth 2004-01-09
  • 打赏
  • 举报
回复
谁帮顶,有分
dlkfth 2004-01-07
  • 打赏
  • 举报
回复
我的邮箱tangh@maritech.com.cn;希望热心高人给俺上一课
dlkfth 2004-01-07
  • 打赏
  • 举报
回复
static
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
System.out.println("success for name");
}
catch(ClassNotFoundException cnfe)
{
System.err.println(cnfe.getMessage());
cnfe.printStackTrace();
}
}
这段代码什么时候执行。
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");为何一定加它,还不用import.
1、Statement对象有何用处。
2、public void doGet(HttpServletRequest request, HttpServletResponse response) 详细解释一下好吗?
3、CachedRowSet crs = new CachedRowSet();//详细讲解一下
crs.populate(dbResultSet); //详细讲解一下
4、 ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream());
//详细讲解一下

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧