Svervlet程序中数据库的动态连接(100分)

T

thewzy

Unregistered / Unconfirmed
GUEST, unregistred user!
各位朋友,我有一个问题:
我编了一个Servlet程序,想在doPost()中连接数据库,可是程序执行之后页面上什么也没有,错误提示也没有。我的代码是这样的:
import java.sql.*
...
public voiddo
Post(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
Connection conn ;
try{
conn = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ERP");
}catch(SQLException e)
{
System.err.println("数据库连接失败!" + e.getMessage());
System.exit(2);
}
....
}
请问那里出了问题。最好那位朋友能给出一代码,最诚挚的谢意!
 
username 和password 都没有,
出错信息被你输出到 控制台去了。
System.err.println("数据库连接失败!" + e.getMessage());
System.exit(2);
改成:out.println("数据库连接失败!" + e.getMessage());
就可以看到错误信息了。
 
改为
try{
conn = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ERP");
}catch(SQLException e)
{
out.println("数据库连接失败!" + e.getMessage());
}
看看它报什么错
还有你的处理代码也没写出来 不知道错在那里??
 
顶部