MySQL datatypes vs JDBC types - mysql

How to find relationship between MySQL datatypes and JDBC types? For example, MySQL TEXT type corresponds to JDBC LONGVARCHAR. Where can we find any official documentation?

MysqlDefs.java
// Maps the given MySQL type to the correct JDBC type.
static int mysqlToJavaType(String mysqlType) {
if (mysqlType.equalsIgnoreCase("BIT")) {
return mysqlToJavaType(FIELD_TYPE_BIT);
} else if (mysqlType.equalsIgnoreCase("TINYINT")) {
return mysqlToJavaType(FIELD_TYPE_TINY);
} else if (mysqlType.equalsIgnoreCase("SMALLINT")) {
return mysqlToJavaType(FIELD_TYPE_SHORT);
} else if (mysqlType.equalsIgnoreCase("MEDIUMINT")) {
return mysqlToJavaType(FIELD_TYPE_INT24);
} else if (mysqlType.equalsIgnoreCase("INT") || mysqlType.equalsIgnoreCase("INTEGER")) {
return mysqlToJavaType(FIELD_TYPE_LONG);
} else if (mysqlType.equalsIgnoreCase("BIGINT")) {
return mysqlToJavaType(FIELD_TYPE_LONGLONG);
} else if (mysqlType.equalsIgnoreCase("INT24")) {
return mysqlToJavaType(FIELD_TYPE_INT24);
} else if (mysqlType.equalsIgnoreCase("REAL")) {
return mysqlToJavaType(FIELD_TYPE_DOUBLE);
} else if (mysqlType.equalsIgnoreCase("FLOAT")) {
return mysqlToJavaType(FIELD_TYPE_FLOAT);
} else if (mysqlType.equalsIgnoreCase("DECIMAL")) {
return mysqlToJavaType(FIELD_TYPE_DECIMAL);
} else if (mysqlType.equalsIgnoreCase("NUMERIC")) {
return mysqlToJavaType(FIELD_TYPE_DECIMAL);
} else if (mysqlType.equalsIgnoreCase("DOUBLE")) {
return mysqlToJavaType(FIELD_TYPE_DOUBLE);
} else if (mysqlType.equalsIgnoreCase("CHAR")) {
return mysqlToJavaType(FIELD_TYPE_STRING);
} else if (mysqlType.equalsIgnoreCase("VARCHAR")) {
return mysqlToJavaType(FIELD_TYPE_VAR_STRING);
} else if (mysqlType.equalsIgnoreCase("DATE")) {
return mysqlToJavaType(FIELD_TYPE_DATE);
} else if (mysqlType.equalsIgnoreCase("TIME")) {
return mysqlToJavaType(FIELD_TYPE_TIME);
} else if (mysqlType.equalsIgnoreCase("YEAR")) {
return mysqlToJavaType(FIELD_TYPE_YEAR);
} else if (mysqlType.equalsIgnoreCase("TIMESTAMP")) {
return mysqlToJavaType(FIELD_TYPE_TIMESTAMP);
} else if (mysqlType.equalsIgnoreCase("DATETIME")) {
return mysqlToJavaType(FIELD_TYPE_DATETIME);
} else if (mysqlType.equalsIgnoreCase("TINYBLOB")) {
return java.sql.Types.BINARY;
} else if (mysqlType.equalsIgnoreCase("BLOB")) {
return java.sql.Types.LONGVARBINARY;
} else if (mysqlType.equalsIgnoreCase("MEDIUMBLOB")) {
return java.sql.Types.LONGVARBINARY;
} else if (mysqlType.equalsIgnoreCase("LONGBLOB")) {
return java.sql.Types.LONGVARBINARY;
} else if (mysqlType.equalsIgnoreCase("TINYTEXT")) {
return java.sql.Types.VARCHAR;
} else if (mysqlType.equalsIgnoreCase("TEXT")) {
return java.sql.Types.LONGVARCHAR;
} else if (mysqlType.equalsIgnoreCase("MEDIUMTEXT")) {
return java.sql.Types.LONGVARCHAR;
} else if (mysqlType.equalsIgnoreCase("LONGTEXT")) {
return java.sql.Types.LONGVARCHAR;
} else if (mysqlType.equalsIgnoreCase("ENUM")) {
return mysqlToJavaType(FIELD_TYPE_ENUM);
} else if (mysqlType.equalsIgnoreCase("SET")) {
return mysqlToJavaType(FIELD_TYPE_SET);
} else if (mysqlType.equalsIgnoreCase("GEOMETRY")) {
return mysqlToJavaType(FIELD_TYPE_GEOMETRY);
} else if (mysqlType.equalsIgnoreCase("BINARY")) {
return Types.BINARY; // no concrete type on the wire
} else if (mysqlType.equalsIgnoreCase("VARBINARY")) {
return Types.VARBINARY; // no concrete type on the wire
} else if (mysqlType.equalsIgnoreCase("BIT")) {
return mysqlToJavaType(FIELD_TYPE_BIT);
} else if (mysqlType.equalsIgnoreCase("JSON")) {
return mysqlToJavaType(FIELD_TYPE_JSON);
}
// Punt
return java.sql.Types.OTHER;
}

Related

Yii2 show error when exception occurs

I have this code in my controller:
...
if (Model::validateMultiple($ttepk)) {
$transaction = \Yii::$app->db->beginTransaction();
try {
foreach ($ttepk as $ttep) {
$ttep->save(false);
if (!$ttep->assignPs()) {
throw new UserException('assignPs failed');
}
}
$transaction->commit();
return $this->redirect(['index']);
} catch (Exception $ex) {
$transaction->rollBack();
throw $ex;
}
}
...
in model:
...
public function assignPs() {
foreach (...) {
$ttepetk[...] = new Ttepet;
$ttepetk[...]->ttepId = $this->id;
... // set other attributes
}
}
if (Model::validateMultiple($ttepetk)) {
foreach ($ttepetk as $ttepet) {
$ttepet->save(false);
}
return true;
} else {
return false;
}
}
...
Everything is working fine (no inserts are happening if any of the models fail validation), except that I would like to see the exact error, exactly by which Ttep (each Ttep is a model) and by which Ttepet (Ttep:Ttepet = 1:N) has the error happened, and what was that. Now I see the Exeption page only, and I don't know how to make the errors visible. Please point me to the right direction. Thanks!
You could iterate on each single model validating one by one and getting the errors when occurs ...
if (Model::validateMultiple($ttepetk)) {
foreach ($ttepetk as $ttepet) {
$ttepet->save(false);
}
return true;
} else {
foreach($ttepetk as $model){
if ($model->validate()) {
// all inputs are valid
} else {
// validation failed: $errors is an array containing error messages
$errors = $model->errors;
}
}
return $errors;
}
you can get the errors this way
$myErrorResult = $ttep->assignPs();
if (!$myErrorResult) {
......

Compare answer from user and possible answer in array

My input text field has two possible answers which are "luah" or "hal" but my code is not working :
stop();
//var jawapan1=Array;
txt_zuhal.addEventListener(KeyboardEvent.KEY_DOWN,handler);
function handler(event:KeyboardEvent)
{
//jawapan1=("luah", "hal");
// if the key is ENTER
if(event.charCode == 13)
{
if(txt_zuhal.text == 'luah'||'hal')
{
trace("1.correct");
}
else
{
trace("1.Sorry, Wrong answer");
}
}
}
private function handler(event:KeyboardEvent):void
{
//jawapan1=("luah", "hal");
// if the key is ENTER
if(event.charCode == 13)
{
if(txt_zuhal.text == "luah" || txt_zuhal.text == "hal")
{
trace("1.correct");
}
else
{
trace("1.Sorry, Wrong answer");
}
}
}

How to print Arabic Text using bluetooth printer in windows phone 8 silver light app?

We need to print Arabic text using Bluetooth Printer in windows phone 8 silver light app. Printing is working fine for English When we are trying to print Arabic text it is not printing as expected? Sample code is given Below:
Public async void PrintTest(string text)
{
var isConnected= await RefreshPairedDevicesList()
if (isConnected)
{
try
{
if (_socket != null)
{
DataWriter writer = new DataWriter(_socket.OutputStream);
writer.WriteString(text);
writer.WriteBytes(Cmd_ESC_JN); // byte[] Cmd_ESC_JN = new byte[] { 27, 74, 230 };
writer.StoreAsync();
}
}
catch { }
}
}
public async Task<bool> RefreshPairedDevicesList()
{
try
{
PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";
var peers = await PeerFinder.FindAllPeersAsync();
if (peers == null && peers.Count == 0)
{
MessageBox.Show("NoPairedDevices");
return false;
}
else
{
// Found paired devices.
foreach (var peer in peers)
{
_pairedDevices.Add(new PairedDeviceInfo(peer));
}
PairedDeviceInfo connectedDeive = _pairedDevices.FirstOrDefault();
var issuccess = await ConnectToDevice(connectedDeive.PeerInfo);
return issuccess;
}
}
catch (Exception ex)
{
if ((uint)ex.HResult == 0x8007048F || (int)ex.HResult == -2147467259)
{
var result = MessageBox.Show(MyStoreWP8AppConstants.Msg_BluetoothOff, "Bluetooth Off", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
ShowBluetoothcControlPanel();
}
return false;
}
else if ((uint)ex.HResult == 0x80070005)
{
MessageBox.Show(MyStoreWP8AppConstants.Msg_MissingCaps);
return false;
}
else
{
MessageBox.Show(ex.Message);
return false;
}
}
}
private async Task<bool> ConnectToDevice(PeerInformation peer)
{
if (_socket != null)
{
_socket.Dispose();
_socket = null;
}
try
{
_socket = new StreamSocket();
string serviceName = peer.ServiceName;
serviceName = String.IsNullOrWhiteSpace(serviceName) ? "1" : serviceName;
await _socket.ConnectAsync(peer.HostName, serviceName);
return true;
}
catch (TaskCanceledException taskEx)
{
return false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
if (_socket != null)
_socket.Dispose();
_socket = null;
return false;
}
}
Could anyone please help us.
Thanks and Regards,
WinitWindowsTeam.

Need the update to always run

I'm using Actionscript 3 and not doing classes, only the actionscript for each panel. I'm trying to make a character creation screen that tells the player how many points they have left after they add them to one of six categories. The score is working, BUT the part that updates the player as to how many points they have left ISN'T. I need it to constantly update to tell the player how many points are left.
var score=0;
var strscore=1;
scorenum.text= update(score); //How I want it displayed.
function update(score) //Brings in the score variable
{
while(score<66) //As you can see I'm trying to make it constantly call here.
//No Good. Calls once.
{
trace("update Score "+score)
var num= 65-score;
scorenum.text= num;
return num;
}
}
strMinus.addEventListener(MouseEvent.CLICK, strMinusFn);
function strMinusFn(event:MouseEvent)
{
if (score<=59)
{
if (strscore >1 && strscore<=50)
{
strscore--;
score--;
}
else
{
strscore==strscore;
}
}
sX.text=strscore;
return score;
}
strPlus.addEventListener(MouseEvent.CLICK, strPlusFn);
function strPlusFn(event:MouseEvent)
{
if (score<=58)
{
if (strscore >=1 && strscore<50)
{
strscore++;
score++;
}
else
{
strscore==strscore;
}
}
sX.text=strscore;
return score;
}
var dexscore=1;
dexMinus.addEventListener(MouseEvent.CLICK, dexMinusFn);
function dexMinusFn(event:MouseEvent)
{
if (score<=59)
{
if (dexscore >1 && dexscore!=50)
{
dexscore--;
score--;
}
else
{
dexscore==dexscore;
}
dX.text=dexscore;
}
return score;
}
dexPlus.addEventListener(MouseEvent.CLICK, dexPlusFn);
function dexPlusFn(event:MouseEvent)
{
if (score<=58)
{
if (dexscore >=1 && dexscore<50)
{
dexscore++;
score++;
}
else
{
dexscore==dexscore;
}
dX.text=dexscore;
}
return score;
}
var intscore=1;
intMinus.addEventListener(MouseEvent.CLICK, intMinusFn);
function intMinusFn(event:MouseEvent)
{
if (score<=59)
{
if (intscore >1 && intscore!=50)
{
intscore--;
score--;
}
else
{
intscore==intscore;
}
iX.text=intscore;
}
return score;
}
intPlus.addEventListener(MouseEvent.CLICK, intPlusFn);
function intPlusFn(event:MouseEvent)
{
if (score<=58)
{
if (intscore >=1 && intscore<50)
{
intscore++;
score++;
}
else
{
intscore==intscore;
}
iX.text=intscore;
}
return score;
}
var conscore=1;
conMinus.addEventListener(MouseEvent.CLICK, conMinusFn);
function conMinusFn(event:MouseEvent)
{
if (score<=59)
{
if (conscore >1 && conscore!=50)
{
conscore--;
score--;
}
else
{
conscore==conscore;
}
cX.text=conscore;
}
return score;
}
conPlus.addEventListener(MouseEvent.CLICK, conPlusFn);
function conPlusFn(event:MouseEvent)
{
if (score<=58)
{
if (conscore >=1 && conscore<50)
{
conscore++;
score++;
}
else
{
conscore==conscore;
}
cX.text=conscore;
}
return score;
}
var wisscore=1;
wisMinus.addEventListener(MouseEvent.CLICK, wisMinusFn);
function wisMinusFn(event:MouseEvent)
{
if (score<=59)
{
if (wisscore >1 && wisscore!=50)
{
wisscore--;
score--;
}
else
{
wisscore==wisscore;
}
wX.text=wisscore;
}
return score;
}
wisPlus.addEventListener(MouseEvent.CLICK, wisPlusFn);
function wisPlusFn(event:MouseEvent)
{
if (score<=58)
{
if (wisscore >=1 && wisscore<50)
{
wisscore++;
score++;
}
else
{
wisscore==wisscore;
}
wX.text=wisscore;
}
return score;
}
var chascore=1;
chaMinus.addEventListener(MouseEvent.CLICK, chaMinusFn);
function chaMinusFn(event:MouseEvent)
{
if (score<=59)
{
if (chascore >1 && chascore!=50)
{
chascore--;
score--;
}
else
{
chascore==chascore;
}
hX.text=chascore;
}
return score;
}
chaPlus.addEventListener(MouseEvent.CLICK, chaPlusFn);
function chaPlusFn(event:MouseEvent)
{
if (score<=58)
{
if (chascore >=1 && chascore<50)
{
chascore++;
score++;
}
else
{
chascore==chascore;
}
hX.text=chascore;
}
return score;
}
You could use a while loop that will update the remainder every time you put a score into a "attribute".
Something along the lines of
while score > 0
if attribute_variable > variable_counter
score -= 1
variable_counter += 1
So the while loop will check if you have any score to put into your attributes. The if statement will be checking to see if you put a point into the specific attribute and the statements inside the if are to update the score and the counter for that specific counter so that the counter recognizes you have put a point into that variable.

Syntax error 1073

I'm getting this compiling error but am not quite sure how to fix it -
1073: Syntax error: expecting a catch or a finally clause.
function __setProp___id98__Dage_APOP_Content_0()
{
if (__setPropDict[__id98_] == undefined || !(int(__setPropDict[__id98_]) >= 1 && int(__setPropDict[__id98_]) <= 5))
{
__setPropDict[__id98_] = currentFrame;
try
{
__id98_["componentInspectorSetting"] = true;
}
catch (e:Error)
{
try
{
}
__id98_["componentInspectorSetting"] = false;
}
catch (e:Error)
{
}
}
return;
} // end
Your catch block has been misplaced. This code is also very redundant, possibly generated from a decompiler?
function __setProp___id98__Dage_APOP_Content_0() {
if (__setPropDict[__id98_] == undefined|| !(int(__setPropDict[__id98_]) >= 1 && int(__setPropDict[__id98_]) <= 5)) {
__setPropDict[__id98_] = currentFrame;
try {
__id98_["componentInspectorSetting"] = true;
} catch (e:Error) {
try {
__id98_["componentInspectorSetting"] = false;
} catch(e:Error) {}
}
}
}