Page 2 of 2 FirstFirst 12
Results 21 to 34 of 34
  1. #21
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,532
    Rep Power
    24

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    Until your SQL Server is functioning properly I wouldn't worry about anything on the Java side.

    If it was me, and there was nothing I really needed on the SQL Server instance, I would remove it and start again with a clean install.

    Not sure why you would have issues with disk space.
    It's not that big an install.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  2. #22
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    To solve the issue I really needed to set in MS SQL Configyration MAnager the TCP/IP IPALL property to:1433.
    Indeed a lot of other things I needed to do to achieve connection. For example, add spring-tx jar, sqljdbc_auth.dll etc. Indeed it was achieved with Windows authentification, but MS SQL does not work. I created QA login set simple password and tried to connect with QA login -- but not got.

  3. #23
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    Indeed I cannot insert Date type in JDBCtemplate.update().
    I use simple sql queryINSERT (String sql = INSERT INTO(Name, Date) VALUES("+name+","+date+")" ) (в jdbc), when if date is of string type I got syntax error - .2011 (the same as in ADO.NET C#). Indeed when I use dao jdbctemplate the parametrization is not allowed? converting and inserting date type invokes the issues. Moreover as I see jdbc allow use just sql.Date, but not more formatting extended util.date.So I put in input field of Spring MVC form the 2011-10-11, the only allowed format for simple valueof() method --Date dd = Date.valueof(inputstring) and when I check in MS SQL Server table I see some initial or default date- 1905-07-25? Why it is so?
    Then I applied more complex options for date insert and convertion:

    Java Code:
    java.util.Date d=null; java.sql.Date dd=null;
     try { DateFormat df=new SimpleDateFormat("YYYY/MM/dd"); d=df.parse(inputstring); 
    dd=new Date(d.getTime()); catch (ParseException e) ... ;
     String sql="INSERT ...VALUES (..."+date+")"; return template.update(sql);
    Then again I got in MS Server table the 1905 or 1899 year in date, or in some modofication when insert is succesfull just NULL instead of Date.
    There is even such moment when I display in UI some transient date variable in that conversion chain, I got date 2 week less than entered -- for instance I put -- 10.01.2016 but I see in that chain -- 28.12.2015? Indeed it is not final -- but final is 1905...??? Why it happened.
    I have looked in google and it says about some Locale issue when got 1905, but it is said about Excell
    So in general -- how insert date type correctly in jdbc/jdbctemplate???

  4. #24
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,532
    Rep Power
    24

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    So, you can talk to SQL Server now?

    And the current issue is with the above code and dates?

    OK.
    Don't use Strings to represent dates for SQL.
    Use a PreparedStatement and use the setDate method.
    At the moment your concatenation is is mucking up something...possibly quotes, or formats, or something. all of which would otherwise be handled by a PreparedStatement.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #25
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    Would you provide reliable examples of using dates insertion with jdbctemplate as it has internal prepared statement?
    there I could use jdbctemplate.update(sql, parameters), where parameters is formed of such kind parameters.put("date", date) -- then INSERT VALUES(:name,:date). Indeed except Date create dby such way as Date date=Date.valueof(inputdatestring) -- that suppose just YYYY-MM-DD -- everything else just return index 1 out of range exception indeed I have just two parameters. Then even joda.Localtime just take Localtime date=Localtime.parse(inputdatestring) in format YYYY-MM-DD.
    So I cannot use preparedstatement here in DAO.
    In general why I get input as 2017-03-10 and got 2016-28-12 -- anyway I convert aforementioned dates accordingly as here: Convert from a java.util.Date Object to a java.sql.Date Object : Date¬*¬ę¬*Data Type¬*¬ę¬*Java Tutorial

  6. #26
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    Would you provide reliable examples of using dates insertion with jdbctemplate as it has internal prepared statement?
    there I could use jdbctemplate.update(sql, parameters), where parameters is formed of such kind parameters.put("date", date) -- then INSERT VALUES(:name,:date). Indeed except Date create dby such way as Date date=Date.valueof(inputdatestring) -- that suppose just YYYY-MM-DD -- everything else just return index 1 out of range exception indeed I have just two parameters. Then even joda.Localtime just take Localtime date=Localtime.parse(inputdatestring) in format YYYY-MM-DD.
    So I cannot use preparedstatement here in DAO.
    In general why I get input as 2017-03-10 and got 2016-28-12 -- anyway I convert aforementioned dates accordingly as here: Convert from a java.util.Date Object to a java.sql.Date Object : Date¬*¬ę¬*Data Type¬*¬ę¬*Java Tutorial

  7. #27
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,532
    Rep Power
    24

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    You use the one that takes a PreparedStatementCreator.
    That way you can assign the parameters correctly:
    Java Code:
    jdbcTemplate.update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection connection) {
            // Create the PS and set all the values.
        }
    });
    Assuming you;re on Java 8 the above can be simplified a bit.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #28
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    I have solved the issue with parameters as template.update (sql,par1,par2) demands such sql string as ... VALUES(?,?).
    Indeed I do not understand why util.date conversion sql.date got such string as 28-12-2015 if I put initially 20-03-2016 or any other date of 2016. Why? sql.Date.valueof(inputstring) accepts just yyyy-mm-dd format indeed work well. So I would like to resolve the conversion issue.

  9. #29
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,532
    Rep Power
    24

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    Don't use that form of the update method.
    Use the one I suggested so you don't have to convert your Date object to a String.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #30
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    I asked why I cannot convert plainly util.Date to sql.Date. Maybe the situation is even worst.
    I take util.date from inputstring of html form in more usable format yyyy.mm.dd or yyyy/mm/dd -- then maybe there is some mishap in convertion. Just after it I convert formatted string to sql.Date but probably there I got 28-12-yyyy, where yyyy is previous of input year. I did not checked in simple "console" Java app -- but such incorrectness happens beforethe Insert or other SQL statement.
    Last edited by ark; 06-10-2017 at 03:42 PM.

  11. #31
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,532
    Rep Power
    24

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    How are you doing the conversion from the request String?
    Can you show the values used (preferably from log statements on the server)?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #32
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    Talking about date string conversion -- I should probably try not GUI application for the first time.
    Indeed there is also related issue -- why I cannot validate the date input field -- with Hibernate validator indeed I imported appropriate class, and I can check if input field is empty.
    I used in this last application Dao class for access MS SQL server db, just using Jdbctemplate class -- could it be considered as using the Spring Data, or whether Spring Data is using relevant JPA with annotations?

  13. #33
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,532
    Rep Power
    24

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    Spring Data is a project in its own right.
    JDBCTemplate is not Spring data.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #34
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    287
    Rep Power
    3

    Default Re: Cannot connect Spring MVC JDBC to ms sql server 2008:CannotGetJdbcConnectionExcep

    Yes, of cause, the Spring, and Java, is enough atomized project, that anticipates a lot of additional modules and libraries.
    Meanwhile when I learned the core (IOC) part of Spring, it was almost not present in MVC, except xml confi files.
    Here I want to ask to questions I was lately faced: 1) How many instances of Controller classes are created in Spring MVC application on web-server? One, two or more. And why?
    The second is irrelevant of java -- but would be glad to see the correct answer. What means the major number in array/sequence -- is that the number that is the biggest or most frequently used in array? If the second -- how to use just one cycle to find 2 major numbers of array?

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 5
    Last Post: 09-25-2012, 06:36 PM
  2. Replies: 6
    Last Post: 02-24-2012, 05:22 PM
  3. Cannot connect to sqlserver 2008 with JDBC
    By alexander.s in forum JDBC
    Replies: 4
    Last Post: 03-13-2011, 01:02 AM
  4. SQL Server 2008 to NetBeans IDE 6.8
    By Wesley Chin in forum JDBC
    Replies: 0
    Last Post: 04-30-2010, 08:13 AM
  5. Connecting to SQL Server 2008 DB
    By Lyle in forum Eclipse
    Replies: 1
    Last Post: 02-22-2009, 05:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •