这是我写的一个数据库连接测试.....不知道为什么在IE不能显示啊 .....也不报错呀....
大虾帮个忙呀 .....
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>jdbc connect of sqlserver</title>
</head>
<body>
<% Connection conn=null;
Statement stm=null;
ResultSet rs=null;
String url=
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=myapp";
String user="sa";
String pwd="admin";
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}catch(ClassNotFoundException e) {e.printStackTrace();}
try{
conn=DriverManager.getConnection(url,user,pwd);
stm=conn.createStatement();
rs=stm.executeQuery("select * from studinfo");
while(rs.next()){
out.println("<tr><td>"+rs.getInt(1)+"</td>");
out.println("<td>"+rs.getString(2)+"</td></tr>");
}
}catch(SQLException ex){ ex.getMessage();}
finally{
if(rs!=null) rs.close();
if(stm!=null) stm.close();
if(conn!=null) conn.close();
}
%>
</body>
</html> 但是我放在JDK上测试是没问题的呀 ....import java.sql.*;
public class DbTest{
private Connection conn;
private Statement stm;
private ResultSet rs;
private String driver;
private String url;
private String user;
private String pwd;
public DbTest(){
driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=myapp";
user="sa";
pwd="admin";
init();
}
public void init(){
try{
Class.forName(driver);
System.out.println("driver is ok");
conn=DriverManager.getConnection(url,user,pwd);
System.out.println("connection is ok");
stm=conn.createStatement();
rs=stm.executeQuery("select * from studinfo");
while(rs.next())
System.out.println(rs.getInt("studid"));
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String args[]){
new DbTest();
}
} 这样是可以得到结果...........
小弟刚学啊 ...不明白哦 .....麻烦给帮个忙哈 !!!!!!!
大虾帮个忙呀 .....
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>jdbc connect of sqlserver</title>
</head>
<body>
<% Connection conn=null;
Statement stm=null;
ResultSet rs=null;
String url=
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=myapp";
String user="sa";
String pwd="admin";
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}catch(ClassNotFoundException e) {e.printStackTrace();}
try{
conn=DriverManager.getConnection(url,user,pwd);
stm=conn.createStatement();
rs=stm.executeQuery("select * from studinfo");
while(rs.next()){
out.println("<tr><td>"+rs.getInt(1)+"</td>");
out.println("<td>"+rs.getString(2)+"</td></tr>");
}
}catch(SQLException ex){ ex.getMessage();}
finally{
if(rs!=null) rs.close();
if(stm!=null) stm.close();
if(conn!=null) conn.close();
}
%>
</body>
</html> 但是我放在JDK上测试是没问题的呀 ....import java.sql.*;
public class DbTest{
private Connection conn;
private Statement stm;
private ResultSet rs;
private String driver;
private String url;
private String user;
private String pwd;
public DbTest(){
driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=myapp";
user="sa";
pwd="admin";
init();
}
public void init(){
try{
Class.forName(driver);
System.out.println("driver is ok");
conn=DriverManager.getConnection(url,user,pwd);
System.out.println("connection is ok");
stm=conn.createStatement();
rs=stm.executeQuery("select * from studinfo");
while(rs.next())
System.out.println(rs.getInt("studid"));
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String args[]){
new DbTest();
}
} 这样是可以得到结果...........
小弟刚学啊 ...不明白哦 .....麻烦给帮个忙哈 !!!!!!!
解决方案 »
- sql备份文件粘贴到WebRoot下打开后,出现中文乱码
- jquery +struts2 路径跳转问题
- 项目发布问题
- 求ewebeditor的jsp版本,要求用的是jdk1.3的
- 有一个类别表,一个商品表,商品表有一个字段是类别,现在我要把所有商品按照类别取
- jsp中调用ireport作的报表,出错了!!!??
- 请各位高手帮我看看什么问题?
- java.sql.ResultSet有没取得总行数的方法?
- ?100分求jsp树的原代码 最好是jsp+js+xml 执行效率要高。(从数据库中动态生成的)(散分)
- 请教各位高手,关于使用JSP与mysql的登录问题!急!急!急!急!急!
- 两个JSP页面传递参数的问题
- 请问:在url中传递多个参数该是怎么写法
我把那三个JAR文件放在了 WEB-INF\lib文件夹下了呀 ...
在common\lib\ 也放了呀 .....
我用jdbcodbc桥连access都没问题哦!!!!
我忘了把数据库文件放到 app server 下了 ....
谢谢你们的提醒了!!!!