datasource

Why do we use a DataSource instead of a DriverManager?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 02:42:19
I am reading the Java JDBC specification (vr. 4) and I encountred this statement: DataSource — this interface was introduced in the JDBC 2.0 Optional Package API. It is preferred over DriverManager because it allows details about the underlying data source to be transparent to the application What I am trying to understand is what the difference is between a Connection and a DataSource , and why it exists. I mean, the block above says that the details about a datasource is transparent to the application, but wouldn't externalizing database properties such as username, password, url etc in a

Not able to set spring.datasource.type

谁都会走 提交于 2019-11-28 01:44:35
问题 I'm trying to setup c3p0 on my spring boot server. This is my config right now spring.datasource.url=jdbc:mysql://url/db spring.datasource.username=username spring.datasource.password=password spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.test-on-borrow=true #spring.datasource.test-while-idle=true spring.datasource.validation-query=SELECT 1 #spring.datasource.time-between-eviction-runs-millis=10000 #spring.datasource.min-evictable-idle-time-millis=30000 spring

Sending an email with an attachment using javamail API

拟墨画扇 提交于 2019-11-28 00:04:34
I am trying to send an email with an attachment file in Java. When I send the email without an attachment I receive the email, but when I add the attachment I don't receive anything and I don't get any error messages. This is the code I am using: public void send () throws AddressException, MessagingException{ //system properties Properties props = new Properties(); props.put("mail.smtp.localhost", "localhost"); props.put("mail.smtp.host",Configurations.getInstance().email_serverIp); /* * create some properties and get the default Session */ session = Session.getDefaultInstance(props, null); /

spring boot autoconfiguration with jdbc template autowiring dataSource issue

。_饼干妹妹 提交于 2019-11-27 20:45:46
问题 I'm new to Spring and to J2EE in general. I'm having trouble using JDBC template with Spring Boot autoconfiguration. What I did was I took the example of RESTful web service provided here and decided to extend it to use JDBC template relational database access. Unfortunately another example provided cannot be useful because the only difficulty which is providing dataSource from xml beans file is not considered. What I tried to solve the issue: Using DAO Impl class as extend of different

Can I configure Grails with no datasource?

与世无争的帅哥 提交于 2019-11-27 20:29:14
I have a Grails app that loads its data from xml files and delivers rss feeds via rome. I don't have any domain classes and my app has no datasource. I don't want Grails to load an in memory hsql db when the application has no need for it. Deleting the DataSource.groovy file prevents me from launching the web app, it seems as though the datasource is required, but is there anything I can do if my application doesn't need a datasource? The following steps work for a new app (Grails 1.1.1) to run without using a datasource: grails create-app nodb cd nodb grails uninstall-plugin hibernate rm

Ubuntu Tomcat7 java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory

倖福魔咒の 提交于 2019-11-27 20:12:20
问题 I'm trying to set up a JDBC DataSource in Tomcat 7 under Ubuntu 12.X, so I added the following to the context.xml file: <Resource name="jdbc/myDS" auth="Container" type="javax.sql.DataSource" maxActive="5" maxIdle="2" maxWait="5000" driverClassName="org.postgresql.Driver" username="usr" password="***" url="jdbc:postgresql://localhost:5432/db" /> Obviously, using the right and tested database user id and password. When I restart Tomcat, I get the this error: Feb 05, 2013 1:10:01 PM org.apache

Binding Combobox Using Dictionary as the Datasource

痞子三分冷 提交于 2019-11-27 18:40:23
I'm using .NET 2.0 and I'm trying to bind a combobox's Datasource to a sorted dictionary. So the error I'm getting is "DataMember property 'Key' cannot be found on the Datasource". SortedDictionary<string, int> userCache = UserCache.getSortedUserValueCache(); userListComboBox.DataSource = new BindingSource(userCache, "Key"); //This line is causing the error userListComboBox.DisplayMember = "Key"; userListComboBox.ValueMember = "Value"; SortedDictionary<string, int> userCache = new SortedDictionary<string, int> { {"a", 1}, {"b", 2}, {"c", 3} }; comboBox1.DataSource = new BindingSource(userCache

Oracle getConnection slow

丶灬走出姿态 提交于 2019-11-27 18:33:04
问题 In a Java project, I am using an ojdbc6 jar <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.1.0</version> <scope>compile</scope> </dependenc> The first time for a day I run, dataSource.getConnection() is fast. Second time is usually okay. The next few times take around 45 seconds. After that, it takes multiple minutes. Once I have the FIRST connection of a given application run, any new connections I get are very very fast. This delay is only getting

How do I manually configure a DataSource in Java?

你说的曾经没有我的故事 提交于 2019-11-27 17:26:54
I'm trying to follow Sun's JDBC tutorial at http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html It gives the following example code: DataSource ds = (DataSource) org.apache.derby.jdbc.ClientDataSource() ds.setPort(1527); ds.setHost("localhost"); ds.setUser("APP") ds.setPassword("APP"); Connection con = ds.getConnection(); This code doesn't compile because the DataSource interface has none of these methods, except for the getConnection() method invoked last. (Here's the javadoc: http://java.sun.com/javase/6/docs/api/javax/sql/DataSource.html ) What am I missing? Edit: I'm

configure Grails app to use JDBC connection pool

 ̄綄美尐妖づ 提交于 2019-11-27 16:26:20
问题 This article suggests Tomcat 7 apps should use a JDBC connection pool instead of a commons-dbcp connection pool. However, the latter is the default for a Grails app, and it's not obvious how to change it. My guess is that I need to define a Spring bean in resources.groovy that overrides a bean that is normally created by default, but I've no idea what this bean should be named or what properties I need to set. 回答1: The easiest thing to do would probably be to use the jdbc-pool plugin. Since