Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!

Wayne Woodrow

Ranch Hand
+ Follow
since Oct 31, 2014
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Wayne Woodrow

Yup the text field is sent in the get request to the survey system.

Hmm, good point about the survey system not properly decoding. I think it should be turning those + signs back into spaces. I'll look into their resources to see if there's another solution also.

As far as converting the + to %20, I think that will do it! I ran a test, and it looks like it's displaying correctly.

7 months ago
Maybe I didn't explain correctly. The text field is passed to another system that I don't have control over in the URL. That application takes the URL parameters and displays them on a web page. This is for our ticketing and survey systems which are two separate applications. The survey system displays the survey form, and uses the URL parameter to display things like created date, customer name, and in the case the title.

This worked perfectly using Javascript's encodeURIComponent() function which encodes with %20. However, it's a little problematic doing it on the client side, so I wanted to handle it with Java.

Kristina thank you for the doc link. I've been looking through them though, and very well could have missed it, but I couldn't find anything on how to use percents instead pluses for the spaces.
Here is the line I'm using in my program:
7 months ago

How can I do URL encoding on spaces using percent symbols instead of the plus sign the way Java does it?

I need to encode a text field that is used in a URL. But when it's displayed back by the web page, it needs to be readable.

Test String: TEST with special characters ~ ` ! @ # $ % ^ & * ( )  _ - + = [ ] { } \ | ; : ' " , . < > / ?

When I encoded this using Java's URLEncoder.encode(String test), it replaced the spaces with plus signs (+). This was the result when the string was returned on the web page:

Result: TEST+with+special+characters+~+`+!+@+#+$+%+^+&+*+(+)++_+-+++=+[+]+{+}+\+|+;+:+'+"+,+.+<+>+/+?

But it's ugly and users can't read it. When using %20, the spaces are properly displayed on output. Also, notice the section with three plus signs in a row (+++), which is the space and which is the plus sign?

Is there a way to force using %20 in Java, or is there another recommended library for doing this encoding?
7 months ago
Sure thing, I believe it's

SQL Server 12.0.5223.6
Connecting from: Windows 10 64-bit
Java Versions: 1.8.0231, 11.0.2, 13.0.1
Microsoft JDBC Driver Versions: Multiple versions of 7 and 8 in the maven repo
Thank you all for your assistance. Yes, I'm not too sure about that SSL aspect of this either. I messed with it for a while longer, but I'm giving up on the Microsoft driver now and will just go with the JTDS.

Knute Snortum wrote:

the SQL server is not making any log entries for failed logins. However, if I use SQL Server Management Studio and attempt a login with bad credentials, I do see an entry for it in the log.

Maybe that means that you are not even getting to the server when using the code.  Have you double checked things like the port?  Is the stack trace the same as the one you posted?

Yes it kind of seems that way. As a test, when I intentionally put the wrong server name or port, I get a different error as expected. However, it doesn't seem to matter what instance name or database name that I use, I still get the same login failed for user error.

To avoid any typing errors, I copy pasted from my code into SQL Server Management Studio and I was able to login just fine. I'm not sure how to dig deeper on this. I simplified the code again and included the stack trace below:

Just another quick update... I did a test using the JTDS driver and it worked fine. I may just switch to this if I can't get the Microsoft driver working soon.

Yes I think it's correct as far as the version. In the POM I'm using the following dependency, and for the shade plugin, I am specifying version 11 for the source and target. On the computer, I am running java version 11.0.2.

Yup so apparently these two values can work around SSL issue according to the article:

I set these two values and also changed the code to use a data source, and then set the properties using methods. This got me back to where I was with the 'Login failed for user...'

Another note, the SQL server is not making any log entries for failed logins. However, if I use SQL Server Management Studio and attempt a login with bad credentials, I do see an entry for it in the log.
So it seems like it's not even making a login attempt. I also tested the code using an incorrect URL and got a different error as expected.

Quick update:
Not sure if I'm headed in the right direction, but I think I needed to specify the authentication type as 'setAuthentication("SqlPassword")' according to the link below:

Once I did this, I got a new error:

I also tried this using 'setAuthentication("ActiveDirectoryIntegrated")' to login using my own AD credentials. The result was the same SSL error above. So, that's the trail I'm on now and hoping it's the correct one.

I am trying to connect to our SQL Server from my program, but I'm encountering an error: Login failed for user 'myUser'. ClientConnectionId:xxxxxx

We have a SQL server running with a user account for reading from the database. I am able to connect using SQL authentication from my computer via SQL Server Management Studio. This is working just fine.
We also have an application server on a separate box that runs our ticketing software. From within that application, I am also able to connect to the database using the same login and basic information (db server name, instance, db name, port).

Since I'm able to connect using both methods and from different boxes with the same account, I'm inclined to think it's not an issue with the account, although I'm a noob with SQL server administration.

Most of the examples that came up in searches had to do with people mixing authentication modes with the wrong connection strings. I don't think I've done that here as my scenario is very simple, but I must be missing something.

Also, the attempts to connect from my application do not show up in the SQL server's log.

Can you please take a look and let me know what you think?

Hi Tim, thanks for the response and the explanation on the webapp directories. I always have to go back and reference that.

I have some good news as well... It's finally working.

The link below has a good example for the embedded Tomcat, and they provide a download of the project files. Although, I had to switch back to JDK 8 for the example, as I was getting a 404 error when doing the 'mvn clean package' using JDK 13.

So then I switched back to my own application, and after making some adjustments it's now serving the index.html page.

Here's what I adjusted:
- Added the directory and targetPath values to the POM

- Copied the Main method contents from the example, with the addition of the 'tomcat.getConnector()' line as mentioned in one of the earlier comments.
 + After some experimenting, the key was setting the appBase with the function 'tomcat.getHost().setAppBase(appBase)'. Also, I had to change the 'tomcat.addContext' function to 'tomcat.addWebapp(contextPath, appBase)'.

- Added the function 'tomcat.getConnector()' that James mentioned ealier in the thread (for Tomcat 9).

Interestingly, it doesn't seem to matter where appBase is set, as long as the folder exists. In the code it's set to '.', but I also tried 'C:/' and 'C:/dev' and it worked just fine.

What's still bugging me is that I don't know how to use 'tomcat.addContext(..., ...)'. It seems like one should be able to use that to serve up a static file. I can almost die happy, but I guess I'll let that go for right now. Perhaps it will become clear a bit further down the road.

Here are the pom and app files in all their glory:

8 months ago

James Kieliszek wrote:I had the same problem. This answer by Christopher Schultz got my tomcat server working again.
was all I needed to add. Tomcat 8 did this automatically, version 9 does not.

Thanks for the information. This got me a step further!

Unfortunately, I just came back to this a year later, and I'm trying to set up another simple example. I made the addition that you showed me above, and would like to serve a simple index.html file from the webapp folder. However, whenever I try to access http://localhost:8080 or http://localhost:8080/index.html, I get a 404 error.

File Structure (attached)

8 months ago
Yup it's working, thanks

Now back to Maven problems, haha.
9 months ago
Okay well, I'm an idiot.

Thank you both for your responses, it got me looking at this more closely. I'm working in windows, but also I was using the terminal through VSCode... and it was a PowerShell Terminal not a CMD. Once I changed the terminal type to CMD it worked perfectly.

I also used your advice and changed the URL to forward slashes instead of the double backslash.

9 months ago

So trying to get back into Java programming, I thought I would start a simple program writing to a SQLITE database. Initially this was a Maven project, but I had problems so got even more basic and just wanted to do a simple single class program. Well, still having trouble right off the bat.

The program and sqlite jdbc driver are located in the same folder. If anybody has some idea on how I can run this successfully, I would appreciate input. It's probably a really stupid mistake I'm sure..

First, I compiled the program using the command:

Second, I attempted to run the program, including the driver in the classpath:

For comparison, I created the same program using IntelliJ instead and was able to run the program through the IDE. The console showed the following command which looks the same in format as mine above:

The resulting error is below:

Here is the program

9 months ago