JSP数据库连接问题[错误信息]
错误信息Theserverencounteredaninternalerror()thatpreventeditfromfulfillingthisrequest.JDB...
错误信息The server encountered an internal error () that prevented it from fulfilling this request.
JDBC驱动装了.环境变量已经写了.JSP无数据库时正常显示,连数据库时候就出错
JSP文件:
<html>
<body>
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<jsp:useBean id="workM" scope="page" class="tax.sqlconn_bean" />
<%
String sql="select * from m_color";
ResultSet rs=workM.executeQuery(sql);
while(rs.next())
{
%>
您的第一个字段内容为:<%=rs.getString(1)%>
<%
}
%>
<%out.print("数据库操作成功,恭喜你!!");%>
<%
workM.closeSelect();
%>
</body>
</html>
BEAN文件
package tax;
import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.lang.*;
public class sqlconn_bean
extends JPanel {
BorderLayout borderLayout1 = new BorderLayout();
String durl="jdbc:microsoft:sqlserver://MS214619:1433;DatabaseName=mydata";
String user="sa";
String password="123456";
Connection cn=null;
Statement stat=null;
ResultSet rs=null;
public sqlconn_bean() {
try {
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
public ResultSet executeQuery(String sql)
{
try{
cn=DriverManager.getConnection(durl,user,password);
stat=cn.createStatement();
rs=stat.executeQuery(sql);
}catch(SQLException sx){sx.printStackTrace();}
catch (Exception e){e.printStackTrace ();}
return rs;
}
public void executeUpdate(String sql)
{
try{
int count;
cn=DriverManager.getConnection(durl,user,password);
stat=cn.createStatement();
count=stat.executeUpdate(sql);
System.out.println(count);
}catch(SQLException sx){sx.printStackTrace();}
catch (Exception e){e.printStackTrace ();}
}
public void close()
{
try{
stat.close();
cn.close();
}catch(SQLException sx){sx.printStackTrace();}
catch (Exception e){e.printStackTrace ();}
}
public void closeSelect()
{
try{
stat.close();
cn.close();
rs.close();
}catch(SQLException sx){sx.printStackTrace();}
catch (Exception e){e.printStackTrace ();}
}
private void jbInit() throws Exception {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn= DriverManager.getConnection(durl,user,password);
stat=conn.createStatement();
setLayout(borderLayout1);
}
} 展开
JDBC驱动装了.环境变量已经写了.JSP无数据库时正常显示,连数据库时候就出错
JSP文件:
<html>
<body>
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<jsp:useBean id="workM" scope="page" class="tax.sqlconn_bean" />
<%
String sql="select * from m_color";
ResultSet rs=workM.executeQuery(sql);
while(rs.next())
{
%>
您的第一个字段内容为:<%=rs.getString(1)%>
<%
}
%>
<%out.print("数据库操作成功,恭喜你!!");%>
<%
workM.closeSelect();
%>
</body>
</html>
BEAN文件
package tax;
import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.lang.*;
public class sqlconn_bean
extends JPanel {
BorderLayout borderLayout1 = new BorderLayout();
String durl="jdbc:microsoft:sqlserver://MS214619:1433;DatabaseName=mydata";
String user="sa";
String password="123456";
Connection cn=null;
Statement stat=null;
ResultSet rs=null;
public sqlconn_bean() {
try {
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
public ResultSet executeQuery(String sql)
{
try{
cn=DriverManager.getConnection(durl,user,password);
stat=cn.createStatement();
rs=stat.executeQuery(sql);
}catch(SQLException sx){sx.printStackTrace();}
catch (Exception e){e.printStackTrace ();}
return rs;
}
public void executeUpdate(String sql)
{
try{
int count;
cn=DriverManager.getConnection(durl,user,password);
stat=cn.createStatement();
count=stat.executeUpdate(sql);
System.out.println(count);
}catch(SQLException sx){sx.printStackTrace();}
catch (Exception e){e.printStackTrace ();}
}
public void close()
{
try{
stat.close();
cn.close();
}catch(SQLException sx){sx.printStackTrace();}
catch (Exception e){e.printStackTrace ();}
}
public void closeSelect()
{
try{
stat.close();
cn.close();
rs.close();
}catch(SQLException sx){sx.printStackTrace();}
catch (Exception e){e.printStackTrace ();}
}
private void jbInit() throws Exception {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn= DriverManager.getConnection(durl,user,password);
stat=conn.createStatement();
setLayout(borderLayout1);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询