不用ODBC不就行了么?
直接找JDBC driver,就可以了啊
不过,好像网上的JDBC driver大部分是要钱的
免费的也有,我用过,可是网站名忘了,自己嗖嗖吧
直接找JDBC driver,就可以了啊
不过,好像网上的JDBC driver大部分是要钱的
免费的也有,我用过,可是网站名忘了,自己嗖嗖吧
解决方案 »
- 请问JAVA 中 “enter”的转义字符是“/r/n”,那么。。。
- JAVA 初级错误
- Oracle连接数据库,结果有点奇怪?
- java私塾是这么对我的,大家进来看看
- 关于ODBC驱动程序
- 一个随机产生若干字母(A-Z间),直到出现字母Q停止,怎么写呀???
- jdk中的rt.jar、tools.jar、dt.jar分别包含的内容是什么?
- 今天去书店看了一下,没有《核心技术,卷I,》第五版了,只有第六版,问问各位,第六版值不值的买?
- 请高手指教--怎么用javac编译互相import的包?
- 请求帮助--关于配置java服务器的问题
- 高手们都看过来!散分啦!(100)
- 很简单的问题怎么没人回答,是不是这里没有高手?
// Obtain our environment naming contextContext initCtx = new InitialContext();Context envCtx = (Context) initCtx.lookup("java:comp/env");// Look up our data sourceDataSource ds = (DataSource) envCtx.lookup("jdbc/EmployeeDB");// Allocate and use a connection from the poolConnection conn = ds.getConnection();... use this connection to access the database ...conn.close();
Use of the JDBC Data Sources JNDI Resource Factory requires that you make an appropriate JDBC driver available to both Tomcat internal classes and to your web application. This is most easily accomplished by installing the driver's JAR file(s) into the $CATALINA_HOME/common/lib directory, which makes the driver available both to the resource factory and to your application.2. Declare Your Resource Requirements
Next, modify the web application deployment descriptor (/WEB-INF/web.xml) to declare the JNDI name under which you will look up preconfigured data source. By convention, all such names should resolve to the jdbc subcontext (relative to the standard java:comp/env naming context that is the root of all provided resource factories. A typical web.xml entry might look like this:
<resource-ref> <description> Resource reference to a factory for java.sql.Connection instances that may be used for talking to a particular database that is configured in the server.xml file. </description> <res-ref-name> jdbc/EmployeDB </res-ref-name> <res-type> javax.sql.DataSource </res-type> <res-auth> Container </res-auth></resource-ref>
WARNING - Be sure you respect the element ordering that is required by the DTD for web application deployment descriptors! See the Servlet Specification for details.3. Code Your Application's Use Of This Resource
A typical use of this resource reference might look like this:
Context initCtx = new InitialContext();Context envCtx = (Context) initCtx.lookup("java:comp/env");DataSource ds = (DataSource) envCtx.lookup("jdbc/EmployeeDB");Connection conn = ds.getConnection();... use this connection to access the database ...conn.close();
Note that the application uses the same resource reference name that was declared in the web application deployment descriptor. This is matched up against the resource factory that is configured in $CATALINA_HOME/conf/server.xml, as described below.4. Configure Tomcat's Resource Factory
To configure Tomcat's resource factory, add an elements like this to the $CATALINA_HOME/conf/server.xml file, nested inside the Context element for this web application (or nested inside a DefaultContext element for the surrounding <Host> or <Engine> element.
<Context ...> ... <Resource name="jdbc/EmployeeDB" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/EmployeeDB"> <parameter> <name>user</name> <value>dbusername</value> </parameter> <parameter> <name>password</name> <value>dbpassword</value> </parameter> <parameter> <name>driverClassName</name> <value>org.hsql.jdbcDriver</value> </parameter> <parameter> <name>driverName</name> <value>jdbc:HypersonicSQL:database</value> </parameter> </ResourceParams> ...</Context>
Note that the resource name (here, jdbc/EmployeeDB) must match the value specified in the web application deployment descriptor. Customize the value of the mail.smtp.host parameter to point at the server that provides SMTP service for your network.This example assumes that you are using the HypersonicSQL database JDBC driver. Customize the driverClassName and driverName parameters to match your actual database's JDBC driver and connection URL.