I'm doing a project with Matlab.
This project is about Thai license plate recognition.
I have a problem with encoding-utf8 (I guess).
The program can recognize and show data in Thai but inserting data in table can't show Thai character. (ex. กข1234 --> ??1234 )
I set collation in utf8_unicode_ci. Did i do anything wrong?
Thank you
Here is some of my code
%# Database
javaaddpath('mysql-connector-java-5.1.6-bin.jar');
host = 'localhost:3306';
user = 'root';
password = '';
dbName = 'smart parking';
%# JDBC parameters
jdbcString = sprintf('jdbc:mysql://%s/%s', host, dbName);
jdbcDriver = 'com.mysql.jdbc.Driver';
%# Create the database connection object
conn = database(dbName, user , password, jdbcDriver, jdbcString);
exec(conn, 'SET character_set_results=UTF-8');
exec(conn, 'SET character_set_client=UTF-8');
exec(conn, 'SET character_set_connection=UTF-8');
exec(conn, 'SET character_set_server=UTF-8');
exec(conn, 'SET NAMES utf8');
% check to make sure that we successfully connected
if isconnection(conn)
SQL_x = ['SELECT * FROM tbl_information WHERE sPlate = ''' R_str ''' AND sOut = 0'];
curs_x = exec(conn, SQL_x);
curs_x = fetch(curs_x);
QUERY_x = curs_x.Data;
if strcmp(QUERY_x, 'No Data') == 1
Plate = R_str;
Sql = ['INSERT INTO tbl_information(sPlate, sTimeIn, sTimeOut, sUse, sPrice, sOut) VALUES(''' Plate ''', ''' datestr(now) ''', '''' , 0, 0, 0)'];
curs = exec(conn, Sql);
end
end
set(handles.text8, 'String', R_str);
drawnow;
Related
I am getting JSON data from a word press database to add them to a mobile app using android studio. However, am facing many problems.
First, I need to keep the post content correctly viewed, but what about the html tags ?
After searching I added JSON_HEX_TAG | JSON_PRETTY_PRINT | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE to my output, but that didn't solve my problem. =
PHP CODE
<?php
header('content-type: application/json; charset=utf-8');
/*
* Created by Belal Khan
* website: www.simplifiedcoding.net
* Retrieve Data From MySQL Database in Android
*/
//database constants
define('DB_HOST', 'localhost');
define('DB_USER', '');
define('DB_PASS', '');
define('DB_NAME', '');
//connecting to database and getting the connection object
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
//Checking if any error occured while connecting
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
function getAttachment($post_title) {
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$stmt = $conn->prepare("SELECT guid,post_title FROM wp_posts WHERE `post_type`='attachment' AND `post_title` = ?");
$conn -> set_charset("utf8");
$stmt->bind_param("s",$post_title);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($guid, $post_title);
$products_attach = array();
if($stmt->num_rows == 1) {
while($stmt->fetch()){
$temp = array();
$temp['guid'] = $guid;
array_push($products_attach, $temp);
}
return $temp['guid'];
}
}
//creating a query
$stmt = $conn->prepare("SELECT ID, post_title, post_content FROM wp_posts WHERE `post_type`='lsvr_document'AND `post_status`= 'publish';");
$conn -> set_charset("utf8");
//executing the query
$stmt->execute();
//binding results to the query
$stmt->bind_result($id, $title, $content);
$products = array();
//traversing through all the result
while($stmt->fetch()){
$temp = array();
$temp['id'] = $id;
$temp['title'] = $title;
$temp['link'] = getAttachment($temp['title']);
$temp['content'] = $content;
array_push($products, $temp);
}
//displaying the result in json format
// echo json_encode($products, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG );
$json = json_encode($products, JSON_HEX_TAG | JSON_PRETTY_PRINT | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
echo $json;
//print_r($products);
?>
Some of the Output
"id": 867,
"title": "إفادة إنجاز بناء مخالف",
"link": "http:\/\/syncsecser.com\/municipal\/wp-content\/uploads\/2020\/09\/إفادة-إنجاز-بناء-مخالف.pdf",
"content": "\u003C!-- wp:heading --\u003E\n\u003Ch2\u003Eالمستندات المرفقة و أماكن إنجازها\u003C\/h2\u003E\n\u003C!-- \/wp:heading --\u003E\n\n\u003C!-- wp:paragraph --\u003E\n\u003Cp\u003E1. طلب موقع من صاحب العلاقة أو من ينوب عنه قانوناً.\u003Cbr\u003E2. إفادة عقارية\u0026nbsp;شاملة.\u003Cbr\u003E3. أي مستند يثبت تاريخ إنجاز المخالفة.\u003C\/p\u003E\n\u003C!-- \/wp:paragraph --\u003E\n\n\u003C!-- wp:table {\u0022className\u0022:\u0022is-style-regular\u0022} --\u003E\n\u003Cfigure id=\u0022table1\u0022 class=\u0022wp-block-table is-style-regular\u0022\u003E\u003Ctable\u003E\u003Ctbody\u003E\u003Ctr\u003E\u003Ctd\u003E\u003Cbr\u003E\u003Cbr\u003E-\u003Cstrong\u003E\u003Cu\u003Eمدّة\u0026nbsp;الإنجاز :\u003C\/u\u003E\u003C\/strong\u003E\u003Cbr\u003E\u0026nbsp;ثلاثة أيام سنداً\u0026nbsp;لتعميم وزير الداخلية والشؤون البلدية والقروية رقم 8\/99.\u003Cbr\u003E\u003Cbr\u003E-\u003Cstrong\u003E\u0026nbsp;الرسوم\u0026nbsp;المتوجبة\u003Cbr\u003E\u003Cbr\u003E\u0026nbsp;\u003C\/strong\u003E\u003Cbr\u003E1.\u0026nbsp;\u0026nbsp;رسم الإفادة الفنية:\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; 2000 ل.ل.\u003Cbr\u003E\u0026nbsp;\u003Cbr\u003E2.\u0026nbsp;\u0026nbsp;رسم طابع مالي:\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;1000 ل.ل.\u003Cbr\u003E\u003C\/td\u003E\u003C\/tr\u003E\u003C\/tbody\u003E\u003C\/table\u003E\u003C\/figure\u003E\n\u003C!-- \/wp:table --\u003E"
},
A simple solution is you can encode your content to base64 and then in your mobile app or any other page you want to parse the content, you can just simply decode this base64.
I accessed MySQL database and fetched the table.
Everything is working fine till that.
when i am trying to save the records in text or other formats i am getting the error
Exit Code Exception exit Code=1: 'Change File Mode By Mask error' (5): Access is denied.
Any help will be appreciated.
object jdbcConnect {
def main(args: Array[String]) {
val url="jdbc:mysql://127.0.0.1:3306/mydb"
val username = "root"
val password = "token_password"
Class.forName("com.mysql.jdbc.Driver").newInstance
//DriverManager.registerDriver(new com.mysql.jdbc.Driver());
val conf = new SparkConf().setAppName("JDB CRDD").setMaster("local[2]").set("spark.executor.memory", "1g")
val sc = new SparkContext(conf)
val myRDD = new JdbcRDD( sc, () =>
DriverManager.getConnection(url,username,password) ,
"select s_Id,issue_date from store_details limit ?, ?",
0, 10, 1, r => r.getString("s_Id") + ", " + r.getString("issue_date"))
myRDD.foreach(println)
myRDD.saveAsTextFile("C:/jdbcrddexamplee")
}
}
Error
17/07/18 11:10:19 ERROR Executor: Exception in task 0.0 in stage 2.0
(TID 2) ExitCodeException exitCode=1: ChangeFileModeByMask error (5):
Access is denied.
at org.apache.hadoop.util.Shell.runCommand(Shell.java:582) at
org.apache.hadoop.util.Shell.run(Shell.java:479) at
org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:773)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:866) at
org.apache.hadoop.util.Shell.execCommand(Shell.java:849) at
org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:733)
at
org.apache.hadoop.fs.RawLocalFileSystem$LocalFSFileOutputStream.(RawLocalFileSystem.java:225)
at
org.apache.hadoop.fs.RawLocalFileSystem$LocalFSFileOutputStream.(RawLocalFileSystem.java:209)
at
org.apache.hadoop.fs.RawLocalFileSystem.createOutputStreamWithMode(RawLocalFileSystem.java:307)
at
org.apache.hadoop.fs.RawLocalFileSystem.create(RawLocalFileSystem.java:296)
at
org.apache.hadoop.fs.RawLocalFileSystem.create(RawLocalFileSystem.java:328)
It seemed to be a permission error. My foolishness...
Make sure to run anything as an admin. Though i will suggest to use dataframe instead of RDD :D
I tried to connect to a mysql database, to fetch table records. I can establish the connection, and 10 records are fetched as well, but then suddenly the code crashes. I don't know why. PS: i am new to scala... Any help would be appreciated.
object jdbcConnect {
def main(args: Array[String]) {
val url="jdbc:mysql://127.0.0.1:3306/mydb"
val username = "root"
val password = "token_password"
Class.forName("com.mysql.jdbc.Driver").newInstance
//DriverManager.registerDriver(new com.mysql.jdbc.Driver());
val conf = new SparkConf().setAppName("JDBC RDD").setMaster("local[2]").set("spark.executor.memory", "1g")
val sc = new SparkContext(conf)
val myRDD = new JdbcRDD( sc, () => DriverManager.getConnection(url,username,password) ,
"select s_Id,issue_date from store_details limit ?, ?",
0, 10, 1, r => r.getString("s_Id") + ", " + r.getString("issue_date"))
myRDD.foreach(println)
myRDD.saveAsTextFile("C:/jdbcrddexamplee")
}
}
ERROR
17/07/16 02:32:24 ERROR Executor: Exception in task 0.0 in stage 1.0 (TID 1)
ExitCodeException exitCode=1: ChangeFileModeByMask error (5): Access is denied. at org.apache.hadoop.util.Shell.runCommand(Shell.java:582)
at org.apache.hadoop.util.Shell.run(Shell.java:479)
at org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:773)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:866)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:849)
at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:733)
at org.apache.hadoop.fs.RawLocalFileSystem$LocalFSFileOutputStream.(RawLocalFileSystem.java:225)
at org.apache.hadoop.fs.RawLocalFileSystem$LocalFSFileOutputStream.(RawLocalFileSystem.java:209)
at org.apache.hadoop.fs.RawLocalFileSystem.createOutputStreamWithMode(RawLocalFileSystem.java:307)
at org.apache.hadoop.fs.RawLocalFileSystem.create(RawLocalFileSystem.java:296)
at org.apache.hadoop.fs.RawLocalFileSystem.create(RawLocalFileSystem.java:328)
at org.apache.hadoop.fs.ChecksumFileSystem$ChecksumFSOutputSummer.(ChecksumFileSystem.java:398)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:461)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:440)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:911)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:804)
It seemed to be a permission error.
My foolishness...
Make sure to run anything as an admin.
Though i will suggest to use dataframe instead of RDD :D
Thanks
I am trying to create a logical replication slot via the java PostgreSQL 42.0.0.jre7 API and this is my code :
String url = "jdbc:postgresql://localhost:5432/sampledb?characterEncoding=utf8";
Properties props = new Properties();
PGProperty.USER.set(props, "postgres");
PGProperty.PASSWORD.set(props, "root");
PGProperty.ASSUME_MIN_SERVER_VERSION.set(props, "9.6");
PGProperty.REPLICATION.set(props, "true");
PGProperty.PREFER_QUERY_MODE.set(props, "simple");
DriverManager.registerDriver(new org.postgresql.Driver());
Connection con = DriverManager.getConnection(url, props);
PGConnection replConnection = con.unwrap(PGConnection.class);
replConnection.getReplicationAPI()
.createReplicationSlot()
.logical()
.withSlotName("logical_replication_slot")
.withOutputPlugin("test_decoding")
.make();
but when i run it I get this exception saying that I have an encoding problem.
Caused by: org.postgresql.util.PSQLException: ERROR: invalid byte sequence for encoding "UTF8": 0xe9 0x71 0x75
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:260)[423:org.postgresql.jdbc41:42.0.0.jre7]
at org.postgresql.replication.fluent.logical.LogicalCreateSlotBuilder.make(LogicalCreateSlotBuilder.java:48)[423:org.postgresql.jdbc41:42.0.0.jre7]
at com.soprahr.hub.replication.postgresql.activator.Activator.start(Activator.java:41)[424:com.soprahr.hub.replication.postgresql:0.0.1.SNAPSHOT]
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)[org.apache.felix.framework-5.6.1.jar:]
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2226)[org.apache.felix.framework-5.6.1.jar:]
... 16 more
This is my postgres config i have tried sql_ascii, utf8 for client encoding but always the same error :
client_encoding = windows-1251 # actually, defaults to database
# encoding
# These settings are initialized by initdb, but they can be changed.
lc_messages = 'French_France.1252' # locale for system error message
# strings
lc_monetary = 'French_France.1252' # locale for monetary formatting
lc_numeric = 'French_France.1252' # locale for number formatting
lc_time = 'French_France.1252' # locale for time formatting
You just need to change the settings into postgres.conf
lc_messages = 'English_United States.1252'
lc_monetary = 'English_United States.1252'
lc_numeric = 'English_United States.1252'
lc_time = 'English_United States.1252'
default_text_search_config = 'pg_catalog.english'
And don't forget to comment "client_encoding = windows-1251".
This should work!
I was trying to run a simple jdbc code [ using jdk 1.6, oracle 10g] as,
package javaapplication2;
import java.text.*;
import java.sql.*;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.BufferedWriter;
/**
* #author animark
*/
public class CallableStatementEx1 {
public CallableStatementEx1(){;}
public static void main(String s[]) throws Exception {
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection con=null;
String url= "jdbc:oracle:thin:#//localhost:1521:orcl" ;
con = DriverManager.getConnection(url,"scott","password");
String query="update emp set HIREDATE=?,ENAME=? where empno=?";
//Step1: Get PreparedStatement
PreparedStatement ps=con.prepareStatement(query);
//Prepare java.sql.Date object
/*
This logic shows how to convert simple String that is in
dd-MM-yyyy format into Date object
*/
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");
java.util.Date d=sdf.parse("26-12-2001");
java.sql.Date newdate=new java.sql.Date(d.getTime());
//Step2: set parameters
ps.setDate(1,newdate);
ps.setString(2,"animark");
ps.setInt(3,7839);
//Step3: execute the query
int i=ps.executeUpdate();
System.out.println("record updated count: "+i);
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}//main
}//class
The code is getting compiled properly. But when I'm trying to run it, i'm getting the following exception..
java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at javaapplication2.CallableStatementEx1.main(CallableStatementEx1.java:19)
I've checked the oracle services and all of them are up and running.
Also, please find the contents of other files as
=================================================================================
tnsnames.ora:
# tnsnames.ora Network Configuration File: C:\oraclexe\app\oracle\product\10.2.0\server\BIN\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
====================================================================================
sqlnet.ora
# sqlnet.ora Network Configuration File: C:\oraclexe\app\oracle\product\10.2.0\server\BIN\network\admin\sqlnet.ora
# Generated by Oracle configuration tools.
# This file is actually generated by netca. But if customers choose to
# install "Software Only", this file wont exist and without the native
# authentication, they will not be able to connect to the database on NT.
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
================================================================================
# listener.ora Network Configuration File: C:\oraclexe\app\oracle\product\10.2.0\server\BIN\network\admin\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = C:\oraclexe\app\oracle\product\10.2.0\server\BIN)
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)
===============================================================================
I'm being able to connect to the instance "orcl" using credentials "scott/password", but when i'm trying to connect using statement
SQL> connect sys/password#orcl as sysdba
I'm getting the following error..
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor.
I've also run LSNRCTL for orcl and found
LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 22-JUL-2012 13:42:30
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
The command completed successfully
Please help me if I'm doing anything wrong here.
Try taking the // out of the connection URL. Instead of
String url= "jdbc:oracle:thin:#//localhost:1521:orcl" ;
try
String url= "jdbc:oracle:thin:#localhost:1521:orcl" ;