当前位置: 技术问答>java相关
Servlet中JDBC连接数据库的问题
来源: 互联网 发布时间:2015-04-16
本文导语: 看下面的代码: import java.util.*; import java.sql.*; import java.io.*; import oracle.jdbc.*; import javax.servlet.*; import javax.servlet.http.*; public class AddMyUsers extends HttpServlet { protected String m_userid; protected String m_userfee; protected...
看下面的代码:
import java.util.*;
import java.sql.*;
import java.io.*;
import oracle.jdbc.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AddMyUsers extends HttpServlet {
protected String m_userid;
protected String m_userfee;
protected String m_username;
protected String m_useraddress;
protected String m_st;
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String[] sName = request.getParameterValues("UserName");
String[] sAddr = request.getParameterValues("UserAddr");
String[] sID = request.getParameterValues("UserID");
String[] sFee = request.getParameterValues("UserFee");
m_userid = sID[0];
m_userfee = sFee[0];
m_username = sName[0];
m_useraddress = sAddr[0];
PrintWriter out = response.getWriter();
out.println("");
out.println("");
String title = "helloworld.title";
out.println("" + title + "");
out.println("");
out.println("");
try{
if (AddUser()==0){
out.println("
out.println("
out.println("
out.println("
out.println("
}
else
out.println("
}
catch(Exception e)
{
}
out.println("");
out.println("");
}
Private int AddUser()
throws SQLException {
String s_step = "";
try
{
Integer nowUser = new Integer(m_userid);
if (nowUser.intValue()
import java.util.*;
import java.sql.*;
import java.io.*;
import oracle.jdbc.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AddMyUsers extends HttpServlet {
protected String m_userid;
protected String m_userfee;
protected String m_username;
protected String m_useraddress;
protected String m_st;
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String[] sName = request.getParameterValues("UserName");
String[] sAddr = request.getParameterValues("UserAddr");
String[] sID = request.getParameterValues("UserID");
String[] sFee = request.getParameterValues("UserFee");
m_userid = sID[0];
m_userfee = sFee[0];
m_username = sName[0];
m_useraddress = sAddr[0];
PrintWriter out = response.getWriter();
out.println("");
out.println("");
String title = "helloworld.title";
out.println("" + title + "");
out.println("");
out.println("");
try{
if (AddUser()==0){
out.println("
User add success!
");out.println("
UserName : "+ sName[0] +"
");out.println("
"+ sAddr[0] +"
");out.println("
"+ sID[0] +"
");out.println("
"+ sFee[0] +"
");}
else
out.println("
"+ m_st +"
");}
catch(Exception e)
{
}
out.println("");
out.println("");
}
Private int AddUser()
throws SQLException {
String s_step = "";
try
{
Integer nowUser = new Integer(m_userid);
if (nowUser.intValue()