Win a copy of Kotlin Cookbook this week in the Kotlin forum!

Mike London

Bartender
+ Follow
since Jul 12, 2002
Forum Moderator
Mike London currently moderates these forums:
Cows and Likes
Cows
Total received
17
In last 30 days
0
Total given
0
Likes
Total received
47
Received in last 30 days
1
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike London

kiros haregewoine wrote:@Mike, why toUpperCase, which is not the requirement of OP.



Yep, agreed. Removed.

Code even simpler now.

Thanks for noticing that.

-- mike
2 weeks ago

salvin francis wrote:even if you don't want the method to be case-sensitive ...

why are both the calls to "toUpperCase" within a loop ?



You're right. I was inferring a requirement and not implementing as efficiently as possible.

I updated the code above to remove the toUpperCase().

Thanks!

-- mike

----

“A program is never less than 90% complete, and never more than 95% complete.”
    – Terry Baker
2 weeks ago

Junilu Lacar wrote:Better yet, realize that what you have there is a conversion formula and that sort of thing might be better represented as a function/method, like so:


This also shows that the names you have used, g and Kg, suggest you have used the wrong formula. When converting kilos to grams, you should expect a larger number, not a smaller one.



That's a good idea if you, Mr. OP, plan to call the code more than once: always make a method. And, pick a good method name as was shown above.

However, since your question was very basic, I didn't elaborate or assume any requirements (I just answered your question).

Enjoy!

-- mike
2 weeks ago
Mr. OP: You're making the code more complicated than it needs to be.

This works fine in my testing and is much simpler with fewer methods.

I also genericized the code so it didn't have hard-coded strings. So, you could now take the below and create a general purpose method.



Prints: Found: 0 occurrences of HI in Hi, the 1st. And hi the 2nd, and Hi the 3rd and hi the 4th

HTH

-- mike
2 weeks ago
For experimentation, I would suggest creating a main() method.

This code might be a good starting point (put inside your class):



----

I would also pick a much better variable name than "g". A program (and variable names) that seems obvious while you're working on it can look totally foreign in a few months or even weeks. So, creating self-documenting variable names is a good practice for you or for the person who might have to maintain your code later.

HTH

-- mike
2 weeks ago
In a simple web service I'm writing, the other programmer is planning to POST 180 fields in JASON format to the service.

Since this probably means I'll need to parse all 180 fields using org.json or similar to create a PreparedStatement, I wanted to first ask if there is a simpler way, short of the time and overhead of an ORM, to parse all these fields?

Having to do ...

pstmt.setInt(1, 87);
pstmt.setString(2, "This String");
pstmt.setString(3, "That String");
pstmt.setInt(4, 5);
.
.
.

180 times is going to be painful.

Simpler approach?

If there's no simpler approach, I'll just get an extra large coffee.

Thanks,

-- mike
3 weeks ago

Peter Liang wrote:Hi,
Please help



Hi Peter,

You need to use, as previously mentioned above, the "Add External Jars" button. Click it and navigate to your SQL Server JDBC driver (the link to download the drivers also posted above and explained).

Once you add the JAR, you should be all set.

I would recommend you pick up a good book on JDBC or watch some videos demonstrating adding a JDBC driver to SQL Server in Eclipse. Check out YouTube.

HTH

- mike
That's a good question. In python the scikit-learn library is so advanced and useful, Python is the go-to language for ML.

I don't know either why Java isn't really in the game here, but just use Python as that's what everyone does, at least mostly, for ML.

-- mike
3 weeks ago
I agree with the other postings here, but Reflection can be useful. I've used it to dynamically invoke a method and Reflection used to be used (still is in a lot of code) to load JDBC drivers (forName() method).

Check out this link: http://tutorials.jenkov.com/java-reflection/methods.html

HTH

-- mike
3 weeks ago
Thanks very much. Great music stuff!

Happy new year to you too.

-- mike
4 weeks ago
I wasn't going to rewrite the entire program for the OP (but of course you're correct).

-- mike
1 month ago
Here's a quick way to print your stars. I left your code mostly intact, but I totally agree, the "stars()" method needs to go as it adds nothing to simply the code. A simple System.out.println() statement in your printStars() method would be more semantically logical.

In your code below I updated, I created a final static variable at the top for the star character.

I also made your helper methods private. You want to preserve "Encapsulation" as much as possible so keep methods private you don't need to access outside your classes.

I renamed your loop variable to be more self-documenting.

Hope this helps.



Code Prints:

*****
***
*********


-- mike
1 month ago
You need to use a utility to "unzip" the ".gz" file.

Then, using the Build Path in Eclipse and "Add External JAR".

-- mike

P.S. The most recent JDBC driver appears to be: "sqljdbc_7.4.1.0_enu.tar.gz"
1 month ago
Your "doConnect()" method is trying to connect to SQL Server.

All I see in your updated build path are libraries for MySQL.  

(Speaking of MySQL, though, there is no reason to have two MySQL JDBC drivers in your build path (per your screenshot above) as that could cause issues with MySQL connections.)

-----

So, .... You need to add the JDBC driver for SQL Server.

Check this page where you can download it if you don't already have it...

https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver15

-- mike
1 month ago