Getting a char(36) UUID from MySQL query [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
What type should I be getting for a char(36) UUID value in a MySQL query?
Query:
ResultSet res = st.executeQuery("SELECT uuid FROM playerdata");
String variable:
String uuid = res.getString("uuid");
The above line is the part I am unsure about. Is a CHAR value a String, an Object, or something else?
Example value:
456f5080-f3b5-11e3-ac10-0800200c9a66
I've tried both strings and objects, but neither seem to work. Just a quick clarification would be greatly appreciated!

Char(36) refers to the datatype of the field in your database. You can store strings up to 36 characters. If you store less than 36 characters, your database will store trailing zeros. In your case, it appears that you are storing UUIDs there, which are 36 character strings.
Since you tagged this as java, you can read this to see what char means in java.
In other contexts, char(36) is a function that will return a dollar sign. The argument of that function has to be an integer and is treated as an ascii code. Sql Server is one such context.

Should be a normal string only.

Related

CharAt in Java 8 [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
The charAt isn't working... It's returning the hash code and not the value of a part in a structure.
Ex.: charAt(0) where is '1' is returning 49 and not 1
What Am I able to do?!
It >>is<< working. It is returning that character as a char which (presumably) you are assigning to an int and printing. The numeric value of the ASCII / Unicode codepoint for the character '1' is 49. If you want to print / display this as a character, cast the int to a char. (Or don't assign it to an int in the first place.)
For the record, the hashCode value returned by Character is identical to the character value. Strictly speaking a char doesn't have a hashCode because it is a primitive value, and primitives don't have methods.

Is there something wrong with my query? Am I using Inner Join wrongly? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I could use some assistance with my exam project, I have a problem with my SQL query for getting a list of volunteers(id) based on the guild(s)(id) they're in, it is a many to many relationship and have decided to use 'Inner Join' to tell my java program what id's are = to each other, but when I run it, it gives me the error 'com.microsoft.sqlserver.jdbc.SQLServerException: The index 1 is out of range.' Which supposedely means that the list I am trying to show is empty? Any immediate thoughts?
This is the many to many relationship between the 3 tables in diagram:
The query to get the volunteer based on guild, first time using the Inner Join statement, so there might be an error here I have overlooked,
Looks like you need some more spaces at the beginning/end of your strings that you are concatenating.
You also need to select columns using a comma between them, not and.
e.g. select firstname, lastname ... instead of select firstname and lastname ...
The '?' in the WHERE statement is considered a String in SQL, and since there were no GuildName with the string 'questionmark' it tried to find a string in the GuildName column where there was non which resulted in an empty list. Also the concatenation of the strings were incorrect since there was no spacing between Volunteer and Inner. Fixed it. Thanks for the replies.

my sql and java [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am new to Java. I received an error in my project while compiling in Java.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
'exit values('1234567','aaa','aaa','aaa','aaa','aaa',0)' at line 1.
exit is a MySQL reserved word and is not allowed as a table name in SQL statements.
Rename the table, or if you really want to use this table name, then put it in backticks:
insert into `exit` values (?,?,?,?,?,?,?)
Refer to this SQL manual
An identifier may be quoted or unquoted. If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it. (Exception: A reserved word that follows a period in a qualified name must be an identifier, so it need not be quoted.) Reserved words are listed at Section 10.3, “Keywords and Reserved Words”.
This StackOverflow answer exactly addresses your query as to how to use reserved words as an identifier.

What data type should i use? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
hi i have a java programming assignment wich include 3 exercice i have done 2 already but in the third one i am dont know wich data type i should use
here is the question :
Write a java program that reads from the user the course code, section and the scores of a student for three exams representing two midterms and a final. The percentage of each of the three exams is of fixed value 30, 30 and 40 percent respectively. Your program computes the final average grade and displays it along with the course code and the section.
Remark: All data, except for the average, must be whole numbers and you should use the most efficient data type that is suitable for this specific exercise.
Sample Run:
Enter your course code: CSCI250
Enter your section: E
Enter the scores of the tests and the final: 97 83 77
CSCI250 E 84.8 (result)
so what i want to know is what is the preferable data type to use for course code ? and char is the one that i should use for section right ?
If you're capturing user input, use a String for everything.
Reason? You may request a number, but the user can type anything. Your code needs to handle bad input.
I think you can use String as data type for Course Code. You can write both numbers and letters by using it. And for section, yes, char will be suitable for it.
Use a String for arbitrary text.
If the section code is always present1 and is never more than character than a char can be used.
However, I would still use a String for consistency, flexibility, and easy of use. The teacher may prefer this based on the "efficient"cy they are going for.
1The is a soft "always": while char cannot represent null a sentinel (eg. '\0' or ' ') can be used to indicate 'no section specified'. Using such a sentinel to supplement null can also (but does not always) lead to more logic work - in particular when the record is displayed.
In any case, it is probably best to not switch to Character just for the null as this is most likely outside of the scope of current course work.

why strings are terminated with null character in java? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Today I have read that strings are terminated with null character in java. But why is it necessary since length of the string is already maintained by the length variable of the sting class ? So it's kind of strange thing to me. Please someone clarify it to me.
Thanks
Java strings are not null terminated. They end with the length in length. You can make a \0 the last character of a Java string, but that doesn't automatically terminate the string. The length of 12<\0>45 would still be 5 and not 2 as in C.
Don't believe everything you read. In the screen shot below, you can see there is no null-termination.
The documentation mentions nothing of the sort. I'd assume that you read wrong.
If some Java implementation null-terminates strings, then it is an implementation detail, but nothing that is guaranteed by the language specification. (And, of course, as assylias notes, Strings may contain U+0000 in Java.) This isn't unheard of, though. VB's strings pointed to the beginning and were null-terminated, making them compatible with normal C APIs and their length was stored before the beginning of the string.
This tactic of having both a length field and keeping the string null terminated is often employe because many libraries and api's expects null terminated strings.
This means that you still get the performance increase of keeping the length seperate and the ability to directly pass your strings to api's wihtout having to create a copy of the string. In short: the best of two worlds at only a bytes expense.

Categories

Resources