eclipse server application doesn't support arabic chars - mysql

i am building a server application using eclipse , and the client is android application
when i used just Java application i can read arabic chars from mysql and can print it correctly to eclipse ,but on server application i can't , the results are question marks like this `?????`
i am trying to print the results on eclipse not on android
my connect to database is :
String unicode = "?useUnicode=yes&characterEncoding=UTF-8";
Class.forName("com.mysql.jdbc.Driver");
con = (Connection) DriverManager.getConnection(
"jdbc:mysql://localhost:3306/ams-competation" + unicode,
username, password);
don't care about android , i am asking how to read and print arabic chars on eclipse server application
EDIT
seems like my problem is from the eclipse not from the connection because when i tried this System.out.println("روما"); , i got question marks
and when i tried to check that question marks with this statements
if(q.getFirstChoice().equals("بيرلو"))
System.out.println("dddd");
the results was dddd , so i can read it correctly from mysql , but my problem on printing the results

The problem is system.out do not support UtF-8 characters so you should be using following code
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
out.println(“some-utf8-string”);
you can also see the reference.
Edited:
Other workaround is
In the Run Configuration, Arguments tab, I added "-Dfile.encoding=UTF-8" to the VM arguments
In the Run configuration, Common tab, I set the Console Encoding to UTF-8

Related

Setting connection string programmatically to obscure db password

I am using a TableAdapter in a dataset in Vb.net winforms (connected to a mysql server) to allow integration of a Devexpress scheduler - I have been using this method for some time; while I know of many of the security flaws of vb.net including decompiling and packet sniffing plain text communication; I am trying to lock down security as much as I can which brings me to my current problem.
The dataset was set up to connect using the .net framework data provider for mysql which requests a Server address, username, password, and DB file - I then get the option of "saving the login credentials in the connection string" or "setting the login credentials in my programming code" for sake of time previously I saved the login credentials.
this adds a setting file (connectionstring)
server=mysqlserveraddress.com;user id=mysqluser;password=mysqlpassword;database=mysqldb;persistsecurityinfo=True
which also means these credentials are saved in plain text in the installation folder for my program
I am trying to transition to including this connectionstring in my programming code however I do not know how to approach it - for non-dataset transactions I have already declared public const in a module which includes the credentials
'database variables
Public Const dbserver As String = "mysqlserveraddress.com"
Public Const dbuser As String = "mysqluser"
Public Const dbpassw As String = "mysqlpassword"
Public Const dbfile As String = "mysqldb"
and I create the connections when needed.
How do I programmatically enter the connection string so it is not visible to the lay-person.
Are you saying that you want to to set the user id and password attributes of an existing connection string at run time? If so then you can use the appropriate connection string builder. I don't use MySQL and Connector/Net but it should look something like this:
Dim builder As New MySqlConnectionStringBuilder(partialConnectionString)
builder.UserId = userId
builder.Password = password
Dim fullConnectionString As String = builder.ConnectionString
Anyone who decompiles your code is going to see that data though. You might consider just storing the whole lot in the config file but encrypting it. For more info on that, check this out:
http://www.vbforums.com/showthread.php?532768-NET-2-0-Protected-Configuration-(Encrypting-Config-Files)

vb.net Code works locally but not on web server

I've an interesting problem. One of my database related code works good on local machine. But it doesn't return anything from when published on the third party web server.
Following is the code snippet :
Public Function getUserAuthDataWithUserId(ByRef Connection As MySqlConnection,
ByVal UserId As String
) As DataTable
Dim cmd As String
cmd = "select * from tbl_md_userauth where tf_userid = '" + UserId + "' "
getUserAuthDataWithUserId = ExecuteSQL(Connection, cmd)
End Function
And the ExecuteSQL function is :
Public Function ExecuteSQL(ByRef Connection As MySqlConnection,
ByVal SQLStatement As String
) As DataTable
Dim ds As New DataSet
Dim da As New MySqlDataAdapter
Try
da = New MySqlDataAdapter(SQLStatement, Connection)
da.Fill(ds, "tbl_Return")
ExecuteSQL = ds.Tables("tbl_Return")
Catch ex As Exception
msgbox ("exception !")
End Try
End Function
Be assured that :
The database table has correct data. And the code works correctly when connecting from local machine to remote desktop.
The code works correctly when using local IIS and local database.
I've also tried republishing the code twice or thrice.
Helpdesk of web server says there is no problem with their server.
Any clue on what is wrong ?
It appears that you are swallowing your exceptions. The code appears to use a msgbox to display the error, but that will appear on the server under a hidden profile and not be sent to the browser for display. You need some other way of displaying or logging the error that works in a web environment.
That being said, are you able to get any connections to the database and just this method is failing, or are all of your database requests failing? I suspect that you are using integrated authentication in your database configuration, but the same user doesn't work on the server because IIS is running as a different user in the app pool. Try changing your development environment to point to your database on the server and see if you get any errors that way. If you are using a hosting environment, I recommend setting up a named user in your database and using that in your connection string rather than using integrated authentication.
Ultimately, it found to be a server side problem. The Helpdesk fixed it. I am yet to know what precisely they have fixed. I'll problably post it over here as soon as I hear from them.
Thanks to all of you guys who've contributed.

CurrentProject.OpenConnection Fails in MS Access 2000

I support a LOB application written in MS Access VBA with a SQL Server back end. One feature of the application is the ability to open a second instance of the application, allowing the users to view/modify two records at the same time.
The first time I open the application it connects and everything works fine. However when I attempt to open the second instance I get the following error message:
-2147467259 - Method "OpenConnection" of object _CurrentProject failed.
This is the line of code executing when the error occurs:
CurrentProject.OpenConnection strConnection
I have stepped through the code and verified that strConnection is the same connection string in both the first and second instances of the application
I'm running out of things to look for. Any ideas are greatly appreciated!
UPDATE: It appears that something is not allowing the second MSACCESS.EXE instance to use the same connection string. My connection string is below, with database and server substituted for the actual database and server.
PROVIDER=SQLOLEDB.1;INTEGRATED SECURITY=SSPI;PERSIST SECURITY INFO=FALSE;INITIAL CATALOG=database;DATA SOURCE=server
Try
MultipleActiveResultSets=True
(http://msdn.microsoft.com/en-us/library/h32h3abf(v=vs.110).aspx)
Would it be better to open a new form from the same application?
dim frm as ShowCar_Form
frm.Show

How to Use RCurl or RMongo via HTTP with Authentication and Self Signed SSL to Read in JSON Data

I am using R to write a program and perform some analyses. The data is being captured by an outside vendor with MongoDB in JSON format. They are providing it to me via a URI on port 443, which they want me to query using cURL. They have authentication in place and self signed SSL.
I can authenticate and dump the data via curl in Windows, however to create a long term sustainable solution it needs to all be done within R.
The vendor says that RCurl "should" work but they aren't providing any support and they basically just don't like the idea of using RMongo and have no comment on it (but if we could make it work that would be awesome, in my opinion).
I have the following packages loaded
- ggplot2
- DBI
- rjson
- RJSONIO (I sometimes don't load this one if I'm using rjson, or visa versa)
- RMongo
- rstudio
- RCurl
The self signed certificate caused issues even with curl, but those were resolved by editing settings in Ruby and then launching a cmd shell with Ruby and using curl that way. I'm not sure if the problems in R are related.
When trying to go the RCurl route I end up with commands/errors like this:
x <- getURL("https://xxx.xx.xxx.xxx:443/db/_authenticate", userpwd="xxxx:xxxxx") }{Error in function (type, msg, asError = TRUE) : couldn't connect to host
and when trying to use RMongo I'm even more clueless...
> mongo <- mongoDbConnect("xxx.xx.xxx.xxx")
username = "xxxx"
password="xxxxxxxxxxxxx"
authenticated <- dbAuthenticate(mongo, username, password)
Feb 25, 2013 4:00:09 PM com.mongodb.DBTCPConnector fetchMaxBsonObjectSize
WARNING: Exception determining maxBSON size using0
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort.open(DBPort.java:224)
at com.mongodb.DBPort.go(DBPort.java:101)
at com.mongodb.DBPort.go(DBPort.java:82)
at com.mongodb.DBPort.findOne(DBPort.java:142)
at com.mongodb.DBPort.runCommand(DBPort.java:151)
at com.mongodb.DBTCPConnector.fetchMaxBsonObjectSize(DBTCPConnector.java:429)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:416)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:193)
at com.mongodb.DBApiLayer$MyCollection._find(DBApiLayer.java:303)
at com.mongodb.DB.command(DB.java:159)
at com.mongodb.DB.command(DB.java:144)
at com.mongodb.DB._doauth(DB.java:503)
at com.mongodb.DB.authenticate(DB.java:440)
at rmongo.RMongo.dbAuthenticate(RMongo.scala:24)
Error in .jcall(rmongo.object#javaMongo, "Z", "dbAuthenticate", username, :
com.mongodb.MongoException$Network: can't call something
Feb 25, 2013 4:00:10 PM com.mongodb.DBPortPool gotError
WARNING: emptying DBPortPool to 127.0.0.1:27017 b/c of error
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:224)
at com.mongodb.DBPort.go(DBPort.java:101)
at com.mongodb.DBPort.go(DBPort.java:82)
at com.mongodb.DBPort.call(DBPort.java:72)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:202)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:303)
at com.mongodb.DB.command(DB.java:159)
at com.mongodb.DB.command(DB.java:144)
at com.mongodb.DB._doauth(DB.java:503)
at com.mongodb.DB.authenticate(DB.java:440)
at rmongo.RMongo.dbAuthenticate(RMongo.scala:24)
any help would be greatly appreciated!
I had an issue in the past with RCurl where I needed to explicitly point it toward the security certificates to get it to work okay. I ended up needing something like this:
out <- postForm("https://url.org/api/",
token="IMATOKEN",
.opts=curlOptions(cainfo="C:/path/aaa.crt"))
I had manually exported the certificate I needed to get that working.
Also, it kind of looks like you should be doing a POST request given that URI, not a GET. Try the postForm() command, maybe?
EDITED TO ADD:
Okay, I think things might be a little more clear if we stepped back a second. Is your goal to get some file from a specific URL (basically, doing a wget but from within R)? Or is your goal to submit a form that subsequently returns the data you need?
IF you are just trying to get something that is behind basic (and also fairly INSECURE) HTTP authentication, you should do two things:
Tell your data provider to use a more secure option
Use the getURL() option as shown (using the www.omegahat.org example you posted about):
Code:
getURL("http://www.omegahat.org/RCurl/testPassword/",.opts=list(userpwd="bob:welcome"))
OR
getURL("http://bob:welcome#www.omegahat.org/RCurl/testPassword/")
Now, if you need to submit a form to get the data, you would generally pass authentication tokens, etc, as parameters (so, in the example above, `token='.

Coldfusion Connection Code

OK, Ive got my site all up - just not working. ahah. I need (I think) the correct code for a connection string to my database etc. I'm using ColdFsuion and Mysql. My code for the connection string is as follows:
<CFQUERY
NAME="cfGossip"
DATASOURCE="mysqlcf_bridgettip"
USERNAME="<bridgettip>"
PASSWORD="<*******>"
>
</CFQUERY>
My DNS on my hosting plan is, well I think is - mysqlcf_bridgettips and on my ColdFusion is cfGossip. I'm not sure which one to use, or if it's even one of them...? It says the error is there when I try access my index.cfm page.
The error over all is :
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be
displayed.
Is it the connection string that is wrong? I would really love any help at all - rewriting my string etc.
Typically ColdFusion is easier to handle by adding datasources via the ColdFusion Administrator: See Adding Data Sources for ColdFusion.
if you cant access the coldfusion administrator and have no control panel to add a datasource you need to ask your host to add a datasource for you with a name. A datasource in this context is different from having the database created - its having the database "registered" with the coldfusion administrator so that it can be referenced via a datasource name
once the datasource is created you can hit it by adding the datasource attribute to the cfquery tag: cfquery name="myquery" datasource="mydatasourcename"
My DNS on my hosting plan is, well I
think is - mysqlcf_bridgettips and on
my ColdFusion is cfGossip.
The coldFusion Administrator should have a datasource that contains your mysqlcf_bridgettips information (CF datasource name, database name, server IP and port, username/password). If you've named that datasource cfGossip in the administrator than your cfquery should look like:
<cfquery name = "variableNameOfYourQuery (ex. qUsers)" datasource = "cfGossip">
I put my username/password in my datasource in the administrator so I don't have it written in my code.
I believe CF5 was the only version of CF that allowed DSN-less connections that would require a "connection string".