datasource name.normally jdbc/ds
解决方案 »
- 如何在javabean中往jsp的application内置对象中写入值?不使用struts2,纯javabean怎么用?不知什么函数获得application
- jsp:useBean的问题……请各位帮忙解决一下
- 关于JSP页面用word显示的问题
- struts string转换为date
- tomcat怎么配置JDK啊
- 我写了个FILTER,但总是重复加载页面!!
- JSP出现的问题,各位大侠帮忙看下是什么原因,该如何解决!
- 是不是Apache POI在生成Excel时,不支持图片的插入?
- session清除
- 网页另存为功能请教。在线等候。。。。
- 和数据库连接时No suitable driver 。。
- 数据库连接问题
oracle驱动程序:http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html或者C:\oracle\ora81\jdbc\lib\classes12.zip(注意版本)
mysql驱动程序:http://www.mysql.com
sqlserver驱动程序:http://www.microsoft.com/china/sql/default.asp 下载setup.exe文件,再安装
二)驱动的安装
1)环境:WIN2K+j2sdk-1_4_1+tomcat连oracle817 将class12.zip文件改名为class12.jar,然后放到你的jsp目录的WEB-INF/lib下就可
连接程序代码如下:
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>
<%String sDBDrvier="oracle.jdbc.driver.OracleDriver";
String user="dq";
String pwd="dqdq";
String sConnStr="jdbc:oracle:thin:@192.168.0.49:1521:test"; //其中test是数据库的sid
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
String sqlStr="select * from t_user";
try{
Class.forName(sDBDrvier);
}
catch(ClassNotFoundException e)
{
System.out.println("数据库驱动类没找到");
}
try{
conn=DriverManager.getConnection(sConnStr,user,pwd);
stmt=conn.createStatement();
rs=stmt.executeQuery(sqlStr);
while(rs.next())
{
out.print(rs.getString("username"));
}
}
catch(SQLException ex)
{
System.out.print(ex.getMessage());
}
%>
报错原因:
The Network Adapter could not establish the connection 这可能是oracle的服务OracleServiceXB和OracleOraHome81TNSListener没有启动
Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=135294976)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4)))) sid错误
No suitable driver 没有安装驱动程序
驱动程序版本不一致
2)环境:WIN2K+j2sdk-1_4_1+tomcat连sql server2000 将msbase.jar,mssqlserver.jar,msutil.jar放到你的jsp目录的WEB-INF/lib下就可
连接程序代码如下:
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>
<%String sDBDrvier="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String user="sa";
String pwd="781213";
String sConnStr="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
String sqlStr="select * from t_user";
try{
Class.forName(sDBDrvier).newInstance();
}
catch(ClassNotFoundException e)
{
System.out.println("数据库驱动类没找到");
}
try{
conn=DriverManager.getConnection(sConnStr,user,pwd);
stmt=conn.createStatement();
rs=stmt.executeQuery(sqlStr);
while(rs.next())
{
out.print(rs.getString("u_name"));
}
}
catch(SQLException ex)
{
System.out.print(ex.getMessage());
}
%>
连接access使用jdbc-odbc桥不配置odbc
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ce)
{
System.out.println("SQLException:"+ce.getMessage());
}
try
{
String DbUrl = "jdbc:odbc:DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)};DSN='';DBQ=E:\\ms.net\\sendmessage\\vbRs232\\mobilemessage.mdb";
String user = "";
String password = "";
Con=DriverManager.getConnection(DbUrl,user,password);
stmt = Con.createStatement();
}
catch(SQLException e)
{
System.out.println("SQLException"+e.getMessage());
}