1. Could not get JDBC Connection; 启动Tomcat的时候出现了这个错 具体信息在下面
数据库监听没有启动,请问你用的什么数据库?
在cmd命令行下执行 lsnrctl start 然后重启tomcat
2. org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted这句是什么意思?
连接池满了。
可以试试重启,不过用上一段时间连接池还是会满的。
如果你是编程的看看是不是改改code,如果不是。。。。 试着link里的修改方法吧。
3. org.apache.commons.dbcp.BasicDataSource是哪个包里的
commons-dbcp...什么版本的就不知道了
这下面有个1.2.1的你可以下下来试试
http://archive.apache.org/dist/commons/dbcp/binaries/commons-dbcp-1.2.1.zip
4. org.apache.commons.dbcp.BasicDataSource在什么jar包中
commons-dbcp .jar
5. 不手动配置ODBC,用Java直接编写程序来配置好ODBC,或者编写bat也行
ODBC 不适合直接在 Java 中使用,因为它使用 C 语言接口。从Java 调用本地 C 代码在安全性、实现、坚固性和程序的自动移植性方面都有许多缺点。从 ODBC C API 到 Java API 的字面翻译是不可取的。例如,Java 没有指针,而 ODBC 却对指针用得很广泛(包括很容易出错的指针"void *")。您可以将 JDBC 想象成被转换为面向对象接口的 ODBC,而面向对象的接口对 Java 程序员来说较易于接收。
ODBC 很难学。它把简单和高级功能混在一起,而且即使对于简单的查询,其选项也极为复杂。相反,JDBC 尽量保证简单功能的简便性,而同时在必要时允许使用高级功能。启用"纯 Java "机制需要象 JDBC 这样的 Java API。如果使用ODBC,就必须手动地将 ODBC 驱动程序管理器和驱动程序安装在每台客户机上.
不用配置ODBC数据源,一种通过jdbc直接连接Access数据库的方法
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=d:\\temp\test.mdb";
//注意:在Driver 和 (*.mdb)之间有一个空格
Connection con = DriverManager.getConnection(url);
java连接SQL数据库方法一:安装Microsoft SQL Server 2000 Driver for JDBC后,将lib目录下的msbase.jar , mssqlserver.jar, msutil.jar 复制到JDK的主目录下,具体是jdk1.4jrelibext . 完成后编写一下代码
原理:使用jdbc-odbc桥进行连接
try{
Connection con;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); //注册驱动
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://你的IP:1433;databaseName=数据库名","sa","你的密码");//
Statement sta = con.createStatement(); //执行sql语句的容器
String str = "select * from 表名";
ResultSet re = sta.executeQuery(str); //执行完的结果赋给 ResultSet
while(re.next()){ //通过游标对数据进行访问
String 字段名= re.getString("字段名");
System.out.println(字段名);
}
方法二:直接连接。
try{
Connection conn;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:Driver={SQL Server};Server=你的IP;uid=sa;pwd=密码;Database=Northwind");
String sql="select * from Categories";
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery(sql);
while (rs.next())
{
String CategoryName=rs.getString("CategoryName");
System.out.println(CategoryName);
}
}
catch(Exception e){
System.out.println(e.toString());
}
6. spring 配置的几个info信息
<bean id="dataSource"class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"value="sun.jdbc.odbc.JdbcOdbcDriver"></property>
<property name="url" value="jdbc:odbc:driver=;DBQ=db.mdb"></property>
<property name="username" value=""></property>
<property name="password" value=""></property>
<property name="maxActive" value="100"></property>
<property name="maxIdle" value="30"></property>
<property name="maxWait" value="500"></property>
<property name="defaultAutoCommit" value="true"></property>
</bean>
其中access数据库放在项目文件夹的根目录下.
7. 如何配置springmvc+hibernate
首先配置web.xml
spring config
contextConfigLocation
/WEB-INF/applicationContext.xml
spring listerner
org.springframework.web.context.ContextLoaderListener
OpenSessionInViewFilter
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
sessionFactoryBeanName
sessionFactory
singleSession
true
flushMode
AUTO
springmvc
org.springframework.web.servlet.DispatcherServlet
2
springmvc
*.do
Spring character encoding filter
org.springframework.web.filter.CharacterEncodingFilter
encoding
utf-8
Spring character encoding filter
/*
404
/error/404.html
30
login.jsp
接下来配置
springmvc-servlet.xml和applicationContext.xml
这两个文件都放在web-inf下面
applicationContext.xml配置如下:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
org.hibernate.dialect.MySQLDialect
true
true
com/ucs/tdc/pojo/AdminInfo.hbm.xml
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
springmvc-servlet.xml配置如下
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/jsp/"
p:suffix=".jsp" />
<!--
-->
contoller
@Controller
public class AdminController {
static Logger log = Logger.getLogger(AdminController.class);
@Resource
private AdminInterFace interFace;
public void setInterFace(AdminInterFace interFace) {
this.interFace = interFace;
}
static Gson gson;
/***普通用户登录**/
@RequestMapping(value = "jsp/user_Log/login")
public boolean user_login(@RequestParam String user_info) {
Boolean flag=false;
UserInfo info=gson.fromJson(user_info, UserInfo.class);
flag =interFace.verifyuser(info);
return flag;
}
/**管理员登录***/
@RequestMapping(value = "jsp/admin_Log/login")
public boolean admin_login(@RequestParam String admininfo) {
Boolean flag=false;
AdminInfo info=gson.fromJson(admininfo, AdminInfo.class);
interFace.verifyAdmin(info);
return flag;
}
}
接口:
public interface AdminInterFace {
public Boolean verifyuser(UserInfo info);
public void verifyAdmin(AdminInfo info);
}
实现类: session自动管理,采用事务处理
@Repository("AdminImpl")
public class AdminImpl extends HibernateDaoSupport implements AdminInterFace{
@Resource
public void setMySessionFactory(SessionFactory sf){
super.setSessionFactory(sf);
}
public boolean verifyAdmin(String adminName,String pw){
String hql="from AdminInfo ";
Object[] params={adminName};
List list =this.getHibernateTemplate().find(hql);
System.out.println(list.size());
AdminInfo info=list.get(0);
System.out.println(info.getUserName()+" "+info.getUserPw());
return false;
}
public Boolean verifyuser(UserInfo info) {
// TODO Auto-generated method stub
return null;
}
public void verifyAdmin(AdminInfo info) {
// TODO Auto-generated method stub
}
}
项目业务处理和数据处理放置在同一个台服务器上,前
8. java hibernate2在保存数据的时候死锁了。大神帮帮忙看看!
首先检查一下你的事物,是不是死循环!!!(这个很有可能是你的事物死循环了) ;
如果没有的话把你的源代码 和 报的错误都发过来 这样看比较能很确定的回答你 - -!
____________________________________________________________________
Object obj[] = getBrandList().toArray();
这行代码以下的能执行到吗? 你确定就数据吗?
如果没有 就吧你的Factory.Biz.update方法的代码我看下