Selecting a value from a database an check if it is true or false - mkannotation

This code always returns true can some please help me out
public boolean plselct(String sqd)
{
try{
String player ;
pm = conn.prepareStatement("SELECT playertype FROM playerdetails where idplayeratrr = ?");
pm.setString(1,sqd );
h= pm.executeQuery();
player = h.getString("playertype");
if ("Goal keeper".equals(player))
{ return true; }
else
return false;
}catch (Exception e)
{}
return false;
}
SelectQu p = new SelectQu();
p.plselct("77");
if(true)
{ System.out.println("Yes"); }
else
{ System.out.println("No"); }

You are checking for if(true)? Did you mean this instead:
SelectQu p = new SelectQu();
if(p.plselct("77"))
{
System.out.println("Yes");
}
else
{
System.out.println("No");
}

Related

string concatenation in android studio java

I am trying to display invalid user credentials in textview by concatenating the invalid fields.So that i get a textview like invalid name,username,contact...at a time.
I want the invalid fields to display at a time.
I have declared a string and tried to concatenate but the result is textview displays all the fields even if its valid one.
boolean flag = true;
String s1,s2,s3,s4,s5;
boolean checkDataEntered() {
if (isEmpty(Name)) {
Name.setBackgroundResource(R.drawable.error);
s1="Full name";
flag = false;
}
if (isEmpty(Username)) {
Username.setBackgroundResource(R.drawable.error);
s2="Username";
flag = false;
}
if (isEmail(EmailId)) {
EmailId.setBackgroundResource(R.drawable.error);
s3="Email";
flag = false;
}
if (flag) {
return true;
} else {
textView7.setText("Please fill"+s1+ s2+ s3) ;
return false;
}
}
This is because you are concatenating all the fields in your else statement.
textView7.setText("Please fill"+s1+ s2+ s3);
But your requirement is to concatenate it only if it is empty. So you should try like,
boolean flag = true;
String error = "";
boolean checkDataEntered() {
if (isEmpty(Name)) {
Name.setBackgroundResource(R.drawable.error);
error += "Full name";
flag = false;
}
if (isEmpty(Username)) {
Username.setBackgroundResource(R.drawable.error);
error += ",Username";
flag = false;
}
if (isEmail(EmailId)) {
EmailId.setBackgroundResource(R.drawable.error);
error += ",Email";
flag = false;
}
if (flag) {
return true;
} else {
textView7.setText("Please fill "+error) ;
return false;
}
}

mybatis interceptor sql log process

i make mybatis sqllog intercepor in my project.
in case. #{__frch_CUST_0} #{__frch_CUST_1} ~~~ #{__frch_CUST_N}
how can i get parameters value "__frch_CUST_n" ?
// mybatis interceptor sql log function
public String getSqlLog(StatementHandler handler)
{
String sql = handler.getBoundSql().getSql();
Object param = handler.getParameterHandler().getParameterObject();
List<ParameterMapping> paramMapping = handler.getBoundSql().getParameterMappings();
// change \? value to replace point
for(ParameterMapping mapping:paramMapping)
{
sql = sql.replaceFirst("\\?", "#{"+mapping.getProperty()+"}");
}
for(ParameterMapping mapping:paramMapping)
{
String sqlparam = "#{"+mapping.getProperty()+"}";
String sqlparamname = mapping.getProperty();
Object sqlparamvalue = ((Map) param).get(sqlparamname);
if( !sqlparamname.startsWith("__frch_") )
{
if(isNull(sqlparamvalue))
{
sql = sql.replace(sqlparam, "NULL");
}
else
{
if(sqlparamvalue instanceof String)
{
try
{
sql = sql.replace(sqlparam, "'"+getSQLString(sqlparamvalue.toString())+"'");
}
catch(Exception e)
{
sql = sql.replace(sqlparam, "'"+getSQLString(sqlparamvalue.toString())+"'");
}
}
else
{
sql = sql.replace(sqlparam, sqlparamvalue.toString());
}
}
}
else
{
**// HOW CAN I DO HERE?**
}
}
return sql;
}
thank you for read my question..
i resolve my self.
mybatis make new arrayList parameter. and use it.
example list value
DATE = ['20180101','20180102','20180103'];
STEP = ['PLAN', 'MAKE', 'SETUP'];
__frch_DATE_0
__frch_DATE_1
__frch_DATE_2
__frch_STEP_3
__frch_STEP_4
__frch_STEP_5
mybatis __frch_ = ['20180101','20180102','20180103','PLAN', 'MAKE', 'SETUP']
so i use it. my question is resolved..
public String getSqlLog(StatementHandler handler)
{
String sql = handler.getBoundSql().getSql();
Object param = handler.getParameterHandler().getParameterObject();
List<ParameterMapping> paramMapping = handler.getBoundSql().getParameterMappings();
List foreachlist = new ArrayList();
for(ParameterMapping mapping:paramMapping)
{
sql = sql.replaceFirst("\\?", "#{"+mapping.getProperty()+"}");
}
for(ParameterMapping mapping:paramMapping)
{
String sqlparam = "#{"+mapping.getProperty()+"}";
String sqlparamname = mapping.getProperty();
Object sqlparamvalue = ((Map) param).get(sqlparamname);
if( !sqlparamname.startsWith("__frch_") )
{
if(isNull(sqlparamvalue))
{
sql = sql.replace(sqlparam, "NULL");
}
else
{
if(sqlparamvalue instanceof String)
{
try
{
sql = sql.replace(sqlparam, "'"+getSQLString(sqlparamvalue.toString())+"'");
}
catch(Exception e)
{
sql = sql.replace(sqlparam, "'"+getSQLString(sqlparamvalue.toString())+"'");
}
}
else
{
sql = sql.replace(sqlparam, sqlparamvalue.toString());
}
}
}
else
{
if( foreachlist.size() == 0 )
{
Map parammap = (Map)param;
Iterator iterator = parammap.keySet().iterator();
while(iterator.hasNext())
{
String key = iterator.next().toString();
Object value = (Object)parammap.get(key);
if( value instanceof List )
{
List valuelist = (List)value;
for(int i=0;i<valuelist.size();i++)
{
foreachlist.add(valuelist.get(i));
}
}
}
}
String buff = sqlparamname.split("__frch_")[1];
int index = Integer.parseInt(buff.substring(buff.lastIndexOf("_")+1));
try
{
sql = sql.replace(sqlparam, "'"+getSQLString((String)foreachlist.get(index))+"'");
}
catch(Exception e)
{
;
}
}
}
return sql;
}

Unity Registeration script not working on 000webhost

I have created a login and registration on unity using php scripts and my database is mysql. Its working fine when I am using phpmyadmine localhost but as soon as I post my scripts on 000webhost .I am unable to insert data through my registration and my login is working fine . please please HELP
PHP SCRIPT
UNTIY CODE
public class Register : MonoBehaviour
{
public GameObject loginAs;
public GameObject username;
public GameObject email;
public GameObject password;
public GameObject confpassword;
public string CurrentMenu = "Login";
public GameObject Message;
private string loginas;
private string Username;
private string Email;
private string Password;
private string ConfPassword;
// private string form;
private bool EmailValid = false;
private string[] Characters = { "a", "b", "c", "d", "e", "f", "g", "h", "i",
"j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z", "A",
"B","C","D","E","F","G","H","I","J","K","L","M","N",
"O","P","Q","R","S","T","U","V","W","X","Y","Z","1",
"2","3","4","5","6","7","8","9","0","_","-"};
private string CreateAccountURL = "https://dbanme.000webhostapp.com/Registeration.php";
// Use this for initialization
void Start()
{
}
IEnumerator CreateAccount()
{
//This is what sends messages to out php script
WWWForm Form = new WWWForm();
//These fields are the variables which we send to out php script
Form.AddField("loginas", loginas);
Form.AddField("Username", Username);
Form.AddField("Email", Email);
Form.AddField("Password", Password);
Form.AddField("ConfPassword", ConfPassword);
WWW CreateAccountWWW = new WWW(CreateAccountURL, Form);
//Wait for php to send something back to php
yield return CreateAccountWWW;
string response = CreateAccountWWW.text;
if (CreateAccountWWW.error != null)
{
string CreateAccountReturn = CreateAccountWWW.text;
if (response.Contains("failed"))
{
Message.GetComponent<Text>().text = response;
//CurrentMenu = "Login";
}
}
else
{
Message.GetComponent<Text>().text = response;
SceneManager.LoadScene("Login");
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Tab))
{
if (username.GetComponent<InputField>().isFocused)
{
email.GetComponent<InputField>().Select();
}
if (email.GetComponent<InputField>().isFocused)
{
password.GetComponent<InputField>().Select();
}
if (password.GetComponent<InputField>().isFocused)
{
confpassword.GetComponent<InputField>().Select();
}
}
}
public void gotologin()
{
SceneManager.LoadScene("Login");
}
//this is the register just telling
public void ButtonRegister()
{
loginas = loginAs.GetComponentInChildren<Text>().text;
if (loginas == "Teacher")
{
loginas = "teacher";
// SceneManager.LoadScene("Login");
}
else if (loginas == "Student")
{
loginas = "student";
// SceneManager.LoadScene("Login");
}
Username = username.GetComponent<InputField>().text;
Email = email.GetComponent<InputField>().text;
Password = password.GetComponent<InputField>().text;
ConfPassword = confpassword.GetComponent<InputField>().text;
if (Username != System.String.Empty && Email != System.String.Empty && Password != System.String.Empty && ConfPassword != System.String.Empty)
{
emailvalidation();
//StartCoroutine(CreateAccount());
}
}
void emailvalidation()
{
bool SW = false;
bool EW = false;
for (int j = 0; j < Characters.Length; j++)
{
if (Email.StartsWith(Characters[j]))
{
SW = true;
}
}
for (int j = 0; j < Characters.Length; j++)
{
if (Email.EndsWith(Characters[j]))
{
EW = true;
}
}
if (SW == true && EW == true)
{
EmailValid = true;
}
else
{
EmailValid = false;
}
bool UN = false;
bool EM = false;
bool PW = false;
bool CPW = false;
if (Username == "")
{
Debug.LogWarning("Username field Empty");
}
if (Email != "")
{
//emailvalidation();
if (EmailValid == true)
{
if (Email.Contains("#"))
{
if (Email.Contains("."))
{
Debug.Log("Form upload complete!");
EM = true;
SceneManager.LoadScene("Login");
StartCoroutine(CreateAccount());
}
else
{
Debug.LogWarning("Email Does not Contain a . sign ");
}
}
else
{
Debug.LogWarning("Email does not contain an # sign");
}
}
else
{
Debug.LogWarning("Email is Incorrect3");
}
}
else
{
Debug.LogWarning("Email field Empty");
}
if (Password != "")
{
if (Password.Length > 5)
{
PW = true;
}
else
{
Debug.LogWarning("Password Must be Atleast 6 Characters long");
}
}
else
{
Debug.LogWarning("Passowrd Field Empty");
}
if (ConfPassword != "")
{
if (ConfPassword == Password)
{
CPW = true;
}
else
{
Debug.LogWarning("Passwords dont Match");
}
}
else
{
Debug.LogWarning("Confirm Password Field is Empty");
}
if (UN == true && EM == true && PW == true && CPW == true)
{
bool Clear = true;
int i = 1;
foreach (char c in Password)
{
if (Clear)
{
Password = "";
Clear = false;
}
i++;
char Encrypted = (char)(c * i);
Password += Encrypted.ToString();
}
username.GetComponent<InputField>().text = "";
email.GetComponent<InputField>().text = "";
password.GetComponent<InputField>().text = "";
confpassword.GetComponent<InputField>().text = "";
}
}
}

Magento 2 - new inscription newsletter error (no such entity with customerId = 0)

I always have this error when I try to register to newsletter in Magento 2. The error is:
No such entity with customerId = 0
If I try to add it directly from database, it works perfectly.
The function is :
vendor/magento/module-newsletter/Model/Subscriber.php
public function subscribe($email)
{
$this->loadByEmail($email);
if (!$this->getId()) {
$this->setSubscriberConfirmCode($this->randomSequence());
}
$isConfirmNeed = $this->_scopeConfig->getValue(
self::XML_PATH_CONFIRMATION_FLAG,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
) == 1 ? true : false;
$isOwnSubscribes = false;
$isSubscribeOwnEmail = $this->_customerSession->isLoggedIn()
&& $this->_customerSession->getCustomerDataObject()->getEmail() == $email;
if (!$this->getId() || $this->getStatus() == self::STATUS_UNSUBSCRIBED
|| $this->getStatus() == self::STATUS_NOT_ACTIVE
) {
if ($isConfirmNeed === true) {
// if user subscribes own login email - confirmation is not needed
$isOwnSubscribes = $isSubscribeOwnEmail;
if ($isOwnSubscribes == true) {
$this->setStatus(self::STATUS_SUBSCRIBED);
} else {
$this->setStatus(self::STATUS_NOT_ACTIVE);
}
} else {
$this->setStatus(self::STATUS_SUBSCRIBED);
}
$this->setSubscriberEmail($email);
}
if ($isSubscribeOwnEmail) {
try {
$customer = $this->customerRepository->getById($this->_customerSession->getCustomerId());
$this->setStoreId($customer->getStoreId());
$this->setCustomerId($customer->getId());
} catch (NoSuchEntityException $e) {
$this->setStoreId($this->_storeManager->getStore()->getId());
$this->setCustomerId(0);
}
} else {
$this->setStoreId($this->_storeManager->getStore()->getId());
$this->setCustomerId(0);
}
$this->setStatusChanged(true);
try {
$this->save();
if ($isConfirmNeed === true
&& $isOwnSubscribes === false
) {
$this->sendConfirmationRequestEmail();
} else {
$this->sendConfirmationSuccessEmail();
}
return $this->getStatus();
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
}

Refresh sticky mobile leaderboard ad slot by changing the content URL in infinite scroll

I want to refresh sticky mobile leaderboard slot when the URL changes in infinite scroll. What do you think is the best way to go? Please let me know if you have any suggestions.
class DFPAds {
constructor() {
this.slots = [];
this.onScroll = throttle(this.loopAds, 300);
this.addEvents();
this.createAdObject = this.createAdObject.bind(this);
this.createSlotForAd = this.createSlotForAd.bind(this);
this.displayAd = this.displayAd.bind(this);
}
static get() {
return DFPAds._instance;
}
static set() {
if (!DFPAds._instance) {
DFPAds._instance = new DFPAds();
return DFPAds._instance;
} else {
throw new Error("DFPAds: instance already initialized");
}
}
addEvents() {
window.addEventListener("scroll", e => this.onScroll());
}
loopAds() {
this.slots.map(slot => this.displayAd(slot));
}
createAdObject(ad) {
let id = ad.id;
let attributes = getDataSet(ad);
let sizes = JSON.parse(attributes.sizes);
let sizeMapping;
if (attributes.sizemapping) {
attributes.sizemapping.length
? (sizeMapping = JSON.parse(attributes.sizemapping))
: (sizeMapping = null);
}
attributes.id = id;
attributes.sizes = sizes;
attributes.sizemapping = sizeMapping;
return attributes;
}
createSlotForAd(adObject) {
let {
id,
adtype,
position,
slotname,
sizes,
sizemapping,
shouldlazyload,
pagenumber,
pageid
} = adObject;
googletag.cmd.push(() => {
let slot = googletag.defineSlot(slotname, sizes, id);
if(position){
slot.setTargeting("position", position);
}
if(pagenumber){
slot.setTargeting("pagenumber", pagenumber);
}
if(pageid){
slot.setTargeting("PageID", pageid)
}
if (sizemapping) {
let mapping = googletag.sizeMapping();
sizemapping.map(size => {
mapping.addSize(size[0], size[1])
});
slot.defineSizeMapping(mapping.build());
}
slot.addService(googletag.pubads());
googletag.display(id);
shouldlazyload
? this.slots.push({ slot: slot, id: id })
: googletag.pubads().refresh([slot]);
console.log("SlotTop", slot)
});
}
displayAd(slot) {
console.log("Slottwo", slot)
let item = document.getElementById(slot.id);
if (item) {
let parent = item.parentElement;
let index = this.slots.indexOf(slot);
let parentDimensions = parent.getBoundingClientRect();
if (
(parentDimensions.top - 300) < window.innerHeight &&
parentDimensions.top + 150 > 0 &&
parent.offsetParent != null
) {
googletag.cmd.push(function() {
googletag.pubads().refresh([slot.slot]);
});
this.slots.splice(index, 1);
}
}
}
setUpAdSlots(context = document) {
let ads = [].slice.call(context.getElementsByClassName("Ad-data"));
if (ads.length) {
ads.map(ad => compose(this.createSlotForAd, this.createAdObject)(ad));
}
}
}
export default DFPAds;
And this is my Infinite Scroll code:
export default class InfiniteScroll {
constructor() {
this._end = document.getElementById('InfiniteScroll-End');
this._container = document.getElementById('InfiniteScroll-Container');
if(!this._end || !this._container)
return;
this._articles = { };
this._triggeredArticles = [];
this._currentArticle = '';
this._apiUrl = '';
this._count = 1;
this._timedOut = false;
this._loading = false;
this._ended = false;
this._viewedParameter = "&alreadyViewedContentIds=";
this._articleSelector = "InfiniteScroll-Article-";
this._articleClass = "Article-Container";
this.setStartData();
this.onScroll = throttle(this.eventScroll, 200);
this.addEvents();
}
addEvents(){
setTimeout(()=>{
window.addEventListener('scroll', (e) => this.onScroll() );
}, 2000);
}
addToStore(article){
this._articles["a" + article.id] = article;
}
addToTriggeredArticles(id){
this._triggeredArticles.push(id);
}
getRequestUrl(){
return this._apiUrl + this._viewedParameter + Object.keys(this._articles).map(key => this._articles[key].id).join();
}
getLastArticle(){
return this._articles[Object.keys(this._articles)[Object.keys(this._articles).length-1]];
}
setStartData() {
let dataset = getDataSet(this._container);
if(dataset.hasOwnProperty('apiurl')){
let article = Article.get();
if(article){
this._apiUrl = dataset.apiurl;
this._currentArticle = "a" + article.id;
this.addToStore(article);
}else{
throw(new Error('Infinite Scroll: Article not initialized.'));
}
}else{
throw(new Error('Infinite Scroll: Start object missing "apiurl" property.'));
}
}
eventScroll() {
if(this.isApproachingNext()){
this.requestNextArticle();
}
if(!this.isMainArticle(this._articles[this._currentArticle].node)){
this.updateCurrentArticle();
}
}
eventRequestSuccess(data){
this._loading = false;
if(data != ''){
if(data.hasOwnProperty('Id') && data.hasOwnProperty('Html') && data.hasOwnProperty('Url')){
this.incrementCount();
let node = document.createElement('div');
node.id = this._articleSelector + data.Id;
node.innerHTML = data.Html;
node.className = this._articleClass;
this._container.appendChild(node);
this.initArticleUpNext({
img: data.Img,
title: data.ArticleTitle,
category: data.Category,
target: node.id
});
this.addToStore(
new Article({
id: data.Id,
node: node,
url: data.Url,
title: data.Title,
count: this._count,
nielsenProps: {
section: data.NeilsenSection,
sega: data.NeilsenSegmentA,
segb: data.NeilsenSegmentB,
segc: data.NeilsenSegmentC
}
})
);
}else{
this._ended = true;
throw(new Error('Infinite Scroll: Response does not have an ID, Url and HTML property'));
}
}else{
this._ended = true;
throw(new Error('Infinite Scroll: No new article was received.'));
}
}
eventRequestError(response){
this._loading = false;
this._ended = true;
throw(new Error("Infinite Scroll: New article request failed."));
}
requestNextArticle(){
if(!this._loading){
this._loading = true;
return API.requestJSON(this.getRequestUrl())
.then(
(response)=>{this.eventRequestSuccess(response)},
(response)=>{this.eventRequestError(response)}
);
}
}
triggerViewEvent(article){
if(article.count > 1 && !this.isAlreadyTriggeredArticle(article.id)){
this.addToTriggeredArticles(article.id);
Tracker.pushView(article.url, article.count);
if(isFeatureEnabled('Nielsen') && Nielsen.get()){
Nielsen.get().eventInfiniteScroll({
id: article.id,
url: article.url,
section: article.nielsenProps.section,
sega: article.nielsenProps.sega,
segb: article.nielsenProps.segb,
segc: article.nielsenProps.segc
});
NielsenV60.trackEvent(article.title);
}
}
}
updateCurrentArticle(){
Object.keys(this._articles).map( key => {
if(this._currentArticle !== key && this.isMainArticle(this._articles[key].node)){
this._currentArticle = key;
this.updateUrl(this._articles[key]);
this.triggerViewEvent(this._articles[key]);
}
});
}
updateUrl(article){
try{
if(history.replaceState){
if(window.location.pathname !== article.url){
history.replaceState('', article.title, article.url);
}
}
}catch(e){}
}
incrementCount(){
this._count = this._count + 1;
}
initArticleUpNext(data){
this.getLastArticle().initUpNext(data);
}
isApproachingNext(){
return window.pageYOffset > this._end.offsetTop - (window.innerHeight * 2) && !this._ended && this._end.offsetTop >= 100;
}
isMainArticle(node){
if(node.getBoundingClientRect){
return (node.getBoundingClientRect().top < 80 && node.getBoundingClientRect().bottom > 70);
}else{
return false;
}
}
isAlreadyTriggeredArticle(id){
return this._triggeredArticles.indexOf(id) > -1;
}
}