Text that contains the apostroph php - java

I have a serious problem. My app retrieves text from an online database, the problem is that if I put a text in the database that contains the apostrophe in the site displays correctly in the application fails me while synchronizing with the database. I also enabled the magic quote gpc but nothing. How can I fix?

First, disable magic_quote_gpc, as the are deprecated/removed
Secondly, look at mysqli_real_escape_string() when sending data to database (which I assumed is your 'synchronizing with the database' is).

You have to escape the apostroph like this:
INSERT INTO my_table (col1, col2) VALUES (123, 'Hello there''s');

use $user_input = mysql_real_esape_string($user_input)

Related

How to use Collate in Hibernate for french char set

Hi I'm trying to use collate on a view which has column name per_va_first_name when I use the following query :
SELECT *
FROM person_view
WHERE NLSSORT(per_va_first_name, 'NLS_SORT = FRENCH_AI') = NLSSORT('mickaël', 'NLS_SORT =FRENCH_AI')
I get the error
ORA-12702: invalid NLS parameter string used in SQL function
I'm new to oracle and this nlssort. Can anyone help me in pointing out what's my mistake?
And at the same time I want to use collate in Hibernate for Java. Same french char set.
Edit:
When I use these commands in sql
alter session set nls_sort=French_AI;
alter session set nls_comp=linguistic;
I get the desired output when this query is executed
SELECT * FROM v_myuser_search_test_ea4 where per_va_first_name like 'Mickaël%'
How to do this in Hibernate? Is there a way I can append 'CI' to French_AI to make it 'French_AI_CI'
According to Oracle documentation found on http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions113.htm#SQLRF51562
you might change your query to
SELECT *
FROM person_view
ORDER BY NLSORT(per_va_first_name, 'NLS_SORT = FRENCH_AI_CI')
Hibernate should understand it, however you are already losing database portability as this is Oracle-specific function.

how to insert the '&' character into data base from java

I am using the webservice that will send the request for one of the column as Dran & Hyle , but i get the exception as a expected valid begining name character. due to the special character &
Below is the insert statement in my java .
public static final String PetInsert= insert into pet values(?,?,?);
I believe set define off will not work in java code , it is understood only by sql developer.
Any help is appreciated
From Java, it is recommended to use PreparedStatement when creating a statement to query the database. Read more in the documentation.
Not so sure, but can it be that in the XML of the web service the error is located? Then somewhere
"Dran & Hyle"
should go into the XML. Normally it is done automatically. So it would be the unlikely case of creating the XML oneself with Strings.
In that case use apache's StringEscapeUtils:
s = StringEscapeUtils.escaleXML(s);
P.S. I found set define off of #aUserHimself plausible.

What is the best way to import an XML string into a SQL Server table

I am working with a 3rd product called JPOS and it has an XMLPackager whereby I get a string from this packager that contains a record in an XML format such as:
<MACHINE><B000>STRING_VALUE</B000><B002>STRING_VALUE</B002><B003>STRING_VALUE</B003><B004>STRING_VALUE</B004><B007>STRING_VALUE</B007><B011>STRING_VALUE</B011><B012>STRING_VALUE</B012><B013>STRING_VALUE</B013><B015>STRING_VALUE</B015><B018>STRING_VALUE</B018><B028>STRING_VALUE</B028><B032>STRING_VALUE</B032><B035>STRING_VALUE</B035><B037>STRING_VALUE</B037><B039>STRING_VALUE</B039><B041>STRING_VALUE</B041><B043>STRING_VALUE</B043><B048>STRING_VALUE</B048><B049>STRING_VALUE</B049><B058>STRING_VALUE</B058><B061>STRING_VALUE</B061><B063>STRING_VALUE</B063><B127>STRING_VALUE</B127></MACHINE>
I have a SQL server table that contains a column for each of the listed. Not that it matters but I could potentially have thru defined with specific STRING_VALUEs. I'm not sure what is the best way to go about this in Java. My understanding is that SQL Server can take an XML string (not document) and do an insert. Is it best to parse each value and then put into a list that populate each value into? This is the first time I've used an XML file and therefore trying to get some help/direction.
Thanks.
Sorry, one of my colleagues was able to help and provide a quick answer. I'll try it from my Java code and it looks like it should work great. Thanks anyway.
Here is the SP that she created whereby I can pass in my XML string and bit value:
CREATE PROCEDURE [dbo].[sbssp_InsertArchivedMessages]
(
#doc varchar(max),
#fromTo bit
)
AS
BEGIN
DECLARE #idoc int, #lastId int
EXEC sp_xml_preparedocument #idoc OUTPUT, #doc
INSERT INTO [dbo].[tblArchivedMessages]
SELECT * FROM OPENXML(#idoc, '/MACHINE', 2) WITH [dbo].[tblArchivedMessages]
SET #lastId = (SELECT IDENT_CURRENT('tblArchivedMessages'))
UPDATE [dbo].[tblArchivedMessages]
SET FromToMach = #fromTo
WHERE ID = #lastId
END
GO
Regards.

Storing Special Character in MySQL

I am using mysql query browser to store the following names in the Person table which contains fields of personNumber and personName. I have the character set of personName at utf-8 and if i insert the name via query browse the query is running correctly but when i try that via JDBC or JPA, the name's special characters become the '?'. What is the problem here?...
The names are
1.Năstase
2.Hrustanović
3.Ogris-Martič and some similar names.
Have you set your connection string correctly?
jdbc:mysql://localhost:3306/administer?characterEncoding=utf8
Try this code
jdbc:mysql://localhost:3306/MY_DB?useUnicode=yes&characterEncoding=UTF8

ms sql2000 arabic problem

I hava a table in ms sql2000 with a column defined as nvarchar
when query this table in java i get data for this column like this :
يا هلا بالشباب الحلوين يا شباب ا٠شلونكو؟.
When i try php with adodb i get the data as it should be ,in arabic.
but i need to use java not php ,please can any one help me.
i use a normal sql statement "select * from news"
i use the latest Microsoft jdbc driver(sqljdbc4.jar).
i have no direct access to the sql server.
That looks to me like an encoding issue, make sure you're using the proper encoding in Java to get the text back. Some variant of unicode obviously.
At every character processing step (getting data, modifying data, saving data, displaying data, etcetera) ensure that you're using UTF-8 character encoding.
If it is a client application, you usually only have to worry about it in the database table and if necessary also the JDBC connection string.
If it is a webapplication, then you need to take more into account: request and response encoding. For GET requests this is an appserver setting and for POST requests and all responses you can set it in the appropriate request/response objects.

Categories