Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: problems with lib imports and statements

  1. #1
    Member
    Join Date
    Apr 2012
    Posts
    57
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default problems with lib imports and statements

    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.jdbc.core.RowMapper;
    import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
    import org.springframework.transaction.annotation.Transactional;
     
    import javax.sql.DataSource;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
     
    public class CustomerManagerImpl implements CustomerManager {
     
        private JdbcTemplate jdbc;
     
     
        public CustomerManagerImpl(DataSource dataSource) {
            this.jdbc = new JdbcTemplate(dataSource);
        }
     
        @Override
        public void deleteCustomer(long id) {
            jdbc.update("DELETE FROM customers WHERE id=?", id);
        }
     
        @Override
        public void updateCustomer(Customer c) {
            jdbc.update("UPDATE customers set fullname=?,address=?,phone=?,email=? where id=?",
                    c.getFullname(), c.getAddress(), c.getPhone(), c.getEmail(), c.getId());
        }
     
        private RowMapper<Customer> customerMapper = new RowMapper<Customer>() {
            @Override
            public Customer mapRow(ResultSet rs, int rowNum) throws SQLException {
                return new Customer(rs.getLong("id"),rs.getString("fullname"),rs.getString("address"),rs.getString("phone"),rs.getString("email"));
            }
        };
     
        @Transactional
        @Override
        public List<Customer> getAllCustomers() {
            return jdbc.query("SELECT * FROM customers", customerMapper);
        }
     
        @Override
        public Customer getCustomerById(long id) {
            return jdbc.queryForObject("SELECT * FROM customers WHERE id=?", customerMapper, id);
        }
     
        @Override
        public void createCustomer(Customer c) {
            SimpleJdbcInsert insertCustomer = new SimpleJdbcInsert(jdbc).withTableName("customers").usingGeneratedKeyColumns("id");
            Map<String, Object> parameters = new HashMap<>(2);
            parameters.put("fullname", c.getFullname());
            parameters.put("address", c.getAddress());
            parameters.put("phone", c.getPhone());
            parameters.put("email", c.getEmail());
            Number id = insertCustomer.executeAndReturnKey(parameters);
            c.setId(id.longValue());
        }
     
    }
    Here you can see the errors:

    errP1.jpgerrP2.jpg


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: problems with lib imports and statements

    Please copy the full text of the error messages and paste it here. Images are too small and hard to read and you can not copy text from them.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Apr 2012
    Posts
    57
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: problems with lib imports and statements

    Oki
    PHP Code:
    javapackage org.springframework.jdbc.core.simple does not exist
    java
    type org.springframework.jdbc.core.RowMapper does not take parameters
    java
    no suitable method found for update(java.lang.String,long)
        
    method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.String,java.lang.Object[]) is not applicable
          
    (actual argument long cannot be converted to java.lang.Object[] by method invocation conversion)
        
    method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.String,java.lang.Object[],int[]) is not applicable
          
    (actual and formal argument lists differ in length)
        
    method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.String,org.springframework.jdbc.core.PreparedStatementSetteris not applicable
          
    (actual argument long cannot be converted to org.springframework.jdbc.core.PreparedStatementSetter by method invocation conversion)
        
    method org.springframework.jdbc.core.JdbcTemplate.update(org.springframework.jdbc.core.PreparedStatementCreator,org.springframework.jdbc.support.KeyHolderis not applicable
          
    (actual argument java.lang.String cannot be converted to org.springframework.jdbc.core.PreparedStatementCreator by method invocation conversion)
        
    method org.springframework.jdbc.core.JdbcTemplate.update(org.springframework.jdbc.core.PreparedStatementCreatoris not applicable
          
    (actual and formal argument lists differ in length)
        
    method org.springframework.jdbc.core.JdbcTemplate.update(org.springframework.jdbc.core.PreparedStatementCreator,org.springframework.jdbc.core.PreparedStatementSetteris not applicable
          
    (actual argument java.lang.String cannot be converted to org.springframework.jdbc.core.PreparedStatementCreator by method invocation conversion)
        
    method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.Stringis not applicable
          
    (actual and formal argument lists differ in length)
    javano suitable method found for update(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.Long)
        
    method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.String,java.lang.Object[]) is not applicable
          
    (actual and formal argument lists differ in length)
        
    method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.String,java.lang.Object[],int[]) is not applicable
          
    (actual and formal argument lists differ in length)
        
    method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.String,org.springframework.jdbc.core.PreparedStatementSetteris not applicable
          
    (actual and formal argument lists differ in length)
        
    method org.springframework.jdbc.core.JdbcTemplate.update(org.springframework.jdbc.core.PreparedStatementCreator,org.springframework.jdbc.support.KeyHolderis not applicable
          
    (actual and formal argument lists differ in length)
        
    method org.springframework.jdbc.core.JdbcTemplate.update(org.springframework.jdbc.core.PreparedStatementCreatoris not applicable
          
    (actual and formal argument lists differ in length)
        
    method org.springframework.jdbc.core.JdbcTemplate.update(org.springframework.jdbc.core.PreparedStatementCreator,org.springframework.jdbc.core.PreparedStatementSetteris not applicable
          
    (actual and formal argument lists differ in length)
        
    method org.springframework.jdbc.core.JdbcTemplate.update(java.lang.Stringis not applicable
          
    (actual and formal argument lists differ in length)
    javatype org.springframework.jdbc.core.RowMapper does not take parameters
    java
    cannot find symbol
      symbol
    :   class SimpleJdbcInsert
      location
    : class cz.muni.fi.pv168.books.CustomerManagerImpl
    java
    cannot find symbol
      symbol
    :   class SimpleJdbcInsert
      location
    : class cz.muni.fi.pv168.books.CustomerManagerImpl
    java
    package org.springframework.jdbc.core.simple does not exist
    java
    type org.springframework.jdbc.core.RowMapper does not take parameters
    java
    cannot find symbol
      symbol
    :   class SimpleJdbcInsert
      location
    : class cz.muni.fi.pv168.books.LeaseManagerImpl
    java
    cannot find symbol
      symbol
    :   class SimpleJdbcInsert
      location
    : class cz.muni.fi.pv168.books.LeaseManagerImpl
    java
    C:\Users\Justy\Desktop\Servlet\books-jdbc\src\main\java\cz\muni\fi\pv168\books\LeaseManagerImpl.java uses unchecked or unsafe operations.
    javaRecompile with -Xlint:unchecked for details

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: problems with lib imports and statements

    package org.springframework.jdbc.core.simple does not exist
    The compiler can not find that package on the classpath. Find the jar file it is in and add it to the classpath.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Apr 2012
    Posts
    57
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: problems with lib imports and statements

    i already add it :/ I added : org.springframework.jdbc-sources-3.0.5.Release, and spring-jdbc-3.0.2Release-sources and jdbc.jar

    Why none of this is working?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: problems with lib imports and statements

    I don't know why the compiler is not finding the package. Are you sure the package is in one of those jar files?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Apr 2012
    Posts
    57
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: problems with lib imports and statements

    Yes it is. I found the jar her: Download org.springframework.jdbc-sources-3.0.5.RELEASE.jar : org.springframework.jdbcoJar File Download

    and it's there. But I have no idea why the compiler doesn't sees it

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: problems with lib imports and statements

    why the compiler doesn't sees it
    That's usually because it is not on the classpath.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Apr 2012
    Posts
    57
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: problems with lib imports and statements

    Strange thing is that i'm having issues only with this one jar. Other jars which I added are working well. I checked how to add it here: classpath - how to add a jar to my lib/ directory in intelliJ and have the classes available for my web.xml? - Stack Overflow

    But it's the same thing as I already did

Similar Threads

  1. Problems with a "if-then and if-then-else" statements
    By jjd712 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 7th, 2012, 12:31 AM
  2. Problem with apache xml-rpc lib
    By tah_206207 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 22nd, 2011, 02:31 PM
  3. How to use static imports
    By helloworld922 in forum Java Programming Tutorials
    Replies: 0
    Last Post: July 3rd, 2010, 11:22 AM
  4. How to use static imports
    By helloworld922 in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: July 3rd, 2010, 11:22 AM
  5. Icon change and lib folder problem
    By LeonLanford in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 21st, 2009, 03:00 AM