关于数据库连接的问题?
tomcat 没有报错,但是请求后的网页上的内容是:
the Wrong about Driver
the Wrong about SQL
说明我的,加载驱动有问下周,数据为连接也有问题?问题出在哪儿?我自己他细看,好像没有问题
<%@page contentType= "text/html;charset=GBK " import= "java.sql.* " %>
<html>
<body bgcolor= "pink ">
<% Connection conn;
String DataBaseDriver= "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
String DataBaseName= "jdbc:microsoft:sqlserver;DatabaseName=StudenttData ";
try
{
Class.forName(DataBaseDriver);
}
catch(
ClassNotFoundException ex)
{
out.println( "the Wrong about Driver "+ " <br> ");
}
try
{
conn=DriverManager.getConnection(DataBaseName, "sa ", " ");
Statement stmt=conn.createStatement();
String sql= "select * from Score where StudentNumber=2 ";
//PreparedStatement pstmt =conn.prepareStatement(sql);
// pstmt.setString(1, "2 ");
//ResultSet rs=pstmt.executeQuery();
ResultSet rs=stmt.executeQuery(sql);
out.println( "StudentNumber: "+rs.getString( "StudnetNumber "));
out.println( "Name: "+rs.getString( "Name "));
out.println( "Chinese: "+rs.getString( "Chinese "));
out.println( "English: "+rs.getString( "English "));
out.println( "Math: "+rs.getString( "Math "));
}
catch(
SQLException se)
{
out.print( "the Wrong about SQL ");
}
%>
</body>
</html>
------解决方案--------------------数据连接jdbc:microsoft:sqlserver;DatabaseName=StudenttData出错
应该改为:
jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=StudenttData
------解决方案--------------------如果用TOMCAT连接池的话。
1.将数据库驱动程序的JAR文件放在Tomcat的 common/lib 中;
2.在server.xml中设置数据源,以MySQL数据库为例,如下:
在 <GlobalNamingResources> </GlobalNamingResources> 节点中加入,
<Resource
name= "jdbc/DBPool "
type= "javax.sql.DataSource "
password= "root "
driverClassName= "com.mysql.jdbc.Driver "
ma