Lost in many Java APIs and XML configurations.
I am trying to create an application using Spring MVC, but am struggling with XML configuration.
I want to be able to connect to mysql database ... but I'm struggling to find some short way to do this. I do not want to use Hibernate or any additional frameworks, JDBC will be adequate as I see fit.
I would just like to create a database connection and access the String variable, which can modify the query if necessary. I think the problem lies in the xml configuration, but I could be wrong.
I inserted the details listed below in the application-context.xml file, but the server cannot be created unless I delete them. I'm not sure I am missing something simple!
<bean id="JdbcDao" class="com.bcash.DbAccess.JdbcDao"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" p:driverClassName="com.mysql.jdbc.Driver" p:url="jdbc:mysql://localhost:3306/db_name" p:username="root" p:password="" destroy-method="close" />
This is the related class I wrote for xml declaration
package com.bcash.DbAccess; import javax.sql.DataSource; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcTemplate; public class JdbcDao { private JdbcTemplate jdbcTemplate; protected String query = "INSERT INTO user('username','email','password','access_level') VALUES ('admin',' test@test.com ','testPassWord','admin')"; public void insertUser(){ try{ jdbcTemplate.update(query); } catch(DataAccessException e){ String error = e.getMessage(); System.out.println(error); } } }
The only error I get is that the server cannot be deployed on line 726 ant build script
<target if="netbeans.home" name="-run-deploy-nb"> <nbdeploy clientUrlPart="${client.urlPart}" debugmode="false" forceRedeploy="${forceRedeploy}"/> </target>
Although, I'm fine with PHP, I'm a little confused as I'm pretty new to Java.
Thank you in advance