This week's book giveaway is in the Agile and Other Processes forum. We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line! See this thread for details.
1. During runtime, I get error: "Resultset is closed". But, if I delete all "rs.close()" lines, it now works fine. This is in SpringHibernateDAOImpl.java. The only thing different is that I'm using sql 2000, and I changed was in applicationContext-hibernate.xml <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"><value>sun.jdbc.odbc.JdbcOdbcDriver</value></property> <property name="url"><value>jdbc dbc:LocalServer2</value></property> <property name="username"><value>deepak</value></property> <property name="password"><value>deepak</value></property>
2. In the "Forgot Password" Page, for sending email: I get error: javax.mail.MessagingException: Could not connect to SMTP host: 192.168.10.14, port: 25; nested exception is: java.net.SocketException: Network is unreachable: no further information. I have no idea what this is and how to configure 'smtp'
1. This is because your jdbc driver that connects to your database is probably closing the result set when you close your statement. This impl class is not done correctly there should be try/catch around each one and on an exception setting the object to null. If it were written like that you wouldn't have seen that error.
2. To send out emails you need to connect to a SMTP (Simple Mail Transfer Protocol) server ( a server that sends out emails). This configuration is in the applicationContext-hibernate.xml file at the very bottom. You have to have an email server running or have access to an email server for this to work properly. If you don't have access to a smtp server, there is a java one that Apache has for free download (I use this a lot for testing) http://james.apache.org/server/index.html. An example of SMTP is if you have a gmail account and you setup your gmail in your Outlook or Thunderbird application to send mail from those applications you have to connect to gmail's smtp server (smtp.gmail.com). Once you connect you give it your username/password to authenticate so it knows who is trying to send the emails, once you authenticate to the smtp server you can send out mail via your acount (email@example.com). This code is doing the same thing, it's trying to connecto to an smtp server and send out emails.
On a side note just looking through the SpringHibernateDaoImpl doesn't really use the power of spring/hibernate. There is a lot of code that could be simplified by using hibernate and spring together. But it's still using a lot of JDBC: For example, in the public Collection getUsersList() method you can just do List allLogins = getHibernateTemplate().loadAll(Login.class);
Hope this helps out a little, and good luck with spring and hibernate. But I'll tell you, once you go through it understand it, it can become very powerful tool, and reduce code dramatically.
Hi Nick !, thank you so much for your detailed reply, I have 2 questions I hope you can answer:
1. Thanks for telling me this, I was wondering if you know any spring-struts-hiberate sites or tutorials that have sample project that I can learn from, any recommendations ?
2. That was a great and detailed explaination of smtp. Am I correct when I say: In my app, I connect to smtp server(has to be connected to internet), and the smtp server will send out the email ? To connect to gmail's smtp server, I need to first go through Outlook, and then connect to gmail's smtp server. If I'm connected to internet, is it possible for me to go directly from my app to connect to gmail's smtp server, just like I would with the Apache smtp?
I'm a new to all this, and I really appreciate all the help and comments you have given me.
1. I don't know any good sites that pull those frameworks together into one application. I think Spring may have some example wars in their distribution. If you download spring there is a samples directory that they have war files/source code. I'm pretty sure they have a spring/hibernate example and a spring mvc vs. struts example. so you can see the diffs between spring mvc and struts. Other than that, I have been thinking about putting together a sample application that would just be downloaded and ready to run. Using Derby for a database, apache James for smtp server (only to send emails) and struts/spring/hibernate or spring/hibernate (using spring mvc). But I haven't had much time to get this done. To learn these frameworks it's just taken time and a lot of examples and trial and error with me. I like to learn the basics of them first and then build off of them, but learning new frameworks takes time.
2. You are correct, an smtp server is just an email server that sends and receives emails. So if you want anything to get past your computer you will have to be connected to the internet (for example you have to connect to gmail's smtp server at smtp.gmail.com, if you ping smtp.gmail.com you'll see it's ip address on the internet). You can test locally, for example I use JAMES to send email to an email account on localhost (my local computer) from localhost. So I have my JAMES email server sending and receiving emails from itself.
On a side note, it's funny you mention gmail I was just writing code to use gmails smtp server last night using spring, currently I use godaddy's with my account there. I started wanting to use gmail because I signed up for google apps, which is really nice.
I don't do it the way above, I actually use spring to configure my mail sender and inject the sender into my services. but it'll do the same thing. I can't totally remember the code I wrote but if something's different I'll post it later.