分类: Java
2010-10-08 21:20:34
这是一个servlet文件->Wel.java.
==============建表sql语句=================
create table t_reg (userName varchar(18) primary key,pass
varchar(16),pass2 varchar(16),email varchar(40));
以下是java源码:
package cn.edu.ytu.db;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
/**
* Servlet implementation class Wel
*/
public class Wel extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doRead(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
public void doRead(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Connection ct = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
// 解决中文乱码
response.setContentType("text/html;charset=GB2312");
PrintWriter pw = response.getWriter();
// 欢迎界面
pw.println("");
pw.println("
用户名 | 密码 | 邮件地址 |
---|---|---|
" + rs.getString(1) + " | ");" + rs.getString(2) + " | ");" + rs.getString(4) + " | ");
chinaunix网友2010-11-21 21:16:08
你好,我做servlet连接oracle数据库时遇到点问题,这些代码很有用,可是还是有点不明白,可以加我Q,给我指点一下吗?Q137501157