小编Tra*_*man的帖子

如何根据用户输入的长查询在PHP中显示MySQL错误?

在PHP中,我试图执行一个取决于用户输入的长MySQL查询.但是,我的查询失败,并显示以下消息:

"Query Failed".
Run Code Online (Sandbox Code Playgroud)

实际上,每当查询失败时我都会打印此消息,但我很难找到导致此失败的原因.不幸的是,我找不到它,因为网页上没有指定错误.有没有办法显示导致网页失败的错误消息?

这是我的代码,

$from = "Findings";
$where = "";

if ($service != null)
{
    $from = $from . ", ServiceType_Lookup";
    $where= "Findings.ServiceType_ID= ServiceType_Lookup.ServiceType_ID AND ServiceType_Name= ". $service;

    if ($keyword != null)
        $where= $where . " AND ";
}

if ($keyword != null)
{
    $where= $where . "Finding_ID LIKE '%$keyword%' OR
                     ServiceType_ID LIKE '%$keyword%' OR
                     Title LIKE '%$keyword%' OR
                     RootCause_ID LIKE '%$keyword%' OR
                     RiskRating_ID LIKE '%$keyword%' OR
                     Impact_ID LIKE '%$keyword%' OR
                     Efforts_ID LIKE '%$keyword%' OR
                     Likelihood_ID LIKE '%$keyword%' OR …
Run Code Online (Sandbox Code Playgroud)

php mysql

23
推荐指数
3
解决办法
13万
查看次数

无法将OnCheckedChangeListener设置为复选框

我想设置OnCheckedChangeListener一个CheckBox,但在运行时我的应用程序退出.我也尝试为我设置听众,我TextView仍然得到相同的结果.有人可以帮忙吗?

import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ListViewActivity extends ListActivity implements OnCheckedChangeListener {

TextView label;
CheckBox checkBox;

public class MyCustomAdapter extends ArrayAdapter<String> {


public MyCustomAdapter(Context context, int textViewResourceId,
String[] objects) {
super(context, textViewResourceId, objects);

 // TODO Auto-generated constructor stub
}

@Override
public …
Run Code Online (Sandbox Code Playgroud)

checkbox android android-listview android-adapter

10
推荐指数
1
解决办法
2万
查看次数

Dijkstra的单源最短路径算法可以在图中检测到无限循环吗?

所以我遇到了这个美丽的问题,要求你编写一个程序,找出有向图中是否存在负无穷短路径.(也可以认为是在图中存在"负循环").这是问题的链接:

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=499

我通过从图中的任何源开始两次运行Bellman Ford算法成功地解决了这个问题.我第二次运行算法时,检查节点是否可以放松.如果是这样,那么图中肯定存在负循环.下面是我的C++代码:

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    int test;
    cin>>test;

    for(int T=0; T<test; T++)
    {

        int node, E;

        cin>>node>>E; 

        int **edge= new int *[E];
        for(int i=0; i<E; i++)
        {
            edge[i]= new int [3];
            cin>>edge[i][0]>>edge[i][1]>>edge[i][2];
        }

        int *d= new int [node];

        bool possible=false;

        for(int i=0; i<node;i++)
        {
            d[i]= 999999999;
        }

        d[node-1]=0;

        for(int i=0; i<node-1; i++)
        {

            for(int j=0; j<E; j++)
            {
                if(d[edge[j][1]]>d[edge[j][0]]+edge[j][2])
                    d[edge[j][1]]=d[edge[j][0]]+edge[j][2];
            }
        }

        // time to judge!
        for(int i=0; i<node-1; i++)
        {

            for(int …
Run Code Online (Sandbox Code Playgroud)

algorithm dijkstra infinite shortest-path bellman-ford

9
推荐指数
1
解决办法
1万
查看次数

在将用户重定向到另一个网页后显示消息

我正在用PHP和MySql做HTML.在用户执行某些数据库操作之后,我的系统将用户重定向到原始数据库页面,以便向他显示更新的表.(我完成了这一部分).同时,我希望在原始页面(系统移动的页面)上向用户显示消息,以通知他操作成功.我怎么可能显示这条消息?

这是我的PHP代码移动到另一页.

Header( 'Location: Database.php');
Run Code Online (Sandbox Code Playgroud)

html javascript php

7
推荐指数
4
解决办法
2万
查看次数

用于找到最小化两个节点之间的最大权重的路径的算法

我想乘车从X市到Y市.我的车有一个小水箱,加油站只存在于道路交叉口(交叉口是节点,道路是边缘).因此,我想采取一条路径,使我在两个加油站之间行驶的最大距离最小化.我可以使用什么有效的算法来找到该路径?蛮力是一个坏的解决方案.我想知道是否存在更有效的算法.

algorithm graph shortest-path graph-algorithm

7
推荐指数
1
解决办法
1626
查看次数

嵌套逻辑表达式的计算方法

我有一个逻辑表达式,我想评估.表达式可以嵌套,由T(True)或F(False)和括号组成.括号"("表示"逻辑或".彼此旁边的两个术语TF(或彼此旁边的任何其他两个组合)应该是ANDED(逻辑与).

例如,表达式:

((TFT)T) = true
Run Code Online (Sandbox Code Playgroud)

我需要一个算法来解决这个问题.我想到首先将表达式转换为析取或连接的正规形式,然后我可以轻松地评估表达式.但是,我找不到一个规范化表达式的算法.有什么建议?谢谢.

问题陈述可以在这里找到:https: //icpcarchive.ecs.baylor.edu/index.php?option = com_onlinejudge&Itemid = 2&category = 378&page = show_problem&issueble = 2967

编辑:我误解了部分问题.在给定的逻辑表达式中,AND/OR运算符与每个括号"(")交替.如果我们要通过树表示表达式,则AND/OR运算符取决于子树的深度级别.但是,它是最初认为最深层的树是AND树.我的任务是通过构建树来评估给定的表达式.感谢下面的答案,澄清了问题的正确要求.

algorithm tree logical-tree conjunctive-normal-form

5
推荐指数
1
解决办法
3013
查看次数

我需要一个java方法,可以从我的API中的任何地方访问,但无法使用API​​从应用程序访问

我正在开发一个java API.在我的开发过程中,我一直面临以下问题:

我在两个不同的包中有两个类.包x中的A类,包y中的B类.我需要类A来访问类B中定义的方法M.因此,应该用于方法M的修饰符是public.但是,我不想让在他/她的java应用程序中使用我的API的开发人员访问方法M.问题是方法M有一个public我提到的修饰符,因此任何人都可以在API中访问它或来自API之外.同时,如果我将方法M的修饰符级别降低到protectedprivate,则类A将无法访问方法M,因为它属于不同的包.我怎么解决这个问题?我唯一的解决方案是在同一个包中有A和B吗?

java api methods access-modifiers modifier

5
推荐指数
1
解决办法
553
查看次数

如何解决使用 RestTemplate 传递 MultipartFile 时出现“No serializer found for class java.io.ByteArrayInputStream”的错误?

我正在尝试将 Spring MultipartFile 从我的应用程序传递到微服务,并使用 RestTemplate,如下所示,

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);

    MultiValueMap<String, Object> body= new LinkedMultiValueMap<>(); 
    body.add("circularAttachment", souqBean.getCircularAttachment()); //MultipartFile 
    body.add("circularEntryId", souqBean.getCircularEntryId());
    body.add("circularTitle", souqBean.getCircularTitle());


    HttpEntity<?> entity = new HttpEntity<MultiValueMap<String, Object>>(body,headers); 


     ResponseEntity<Boolean> response =    restTemplate.postForEntity("http://localhost:8081/circular-save", entity, Boolean.class);
     status=response.getBody();
Run Code Online (Sandbox Code Playgroud)

有关更多信息,以下是getCircularAttachment()方法

public MultipartFile getCircularAttachment() {
        return circularAttachment;
    }
Run Code Online (Sandbox Code Playgroud)

其中 MultipartFile 是 Spring 中的一个类: org.springframework.web.multipart.MultipartFile

但在这条线上,

ResponseEntity<Boolean> response =    restTemplate.postForEntity("http://localhost:8081/circular-save", entity, Boolean.class);
 status=response.getBody();
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: No serializer found for class java.io.ByteArrayInputStream and no properties discovered to create BeanSerializer (to …
Run Code Online (Sandbox Code Playgroud)

java post multipartform-data resttemplate microservices

5
推荐指数
1
解决办法
9344
查看次数

FrameworkEvent ERROR运行Hello World OSGI Bundle

我是OSGI的初学者.我按照以下教程在eclipse中做了一个简单的Hello World OSGI Bundle. http://www.javaworld.com/javaworld/jw-03-2008/jw-03-osgi1.html?page=2

在运行项目时,我在控制台中收到一堆错误.以下是这些错误:

osgi> !SESSION 2013-07-10 23:23:03.340 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.7.0_07
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Command-line arguments:  -dev file:C:/Users/student/workspace/.metadata/.plugins/org.eclipse.pde.core/OSGi Framework/dev.properties -os win32 -ws win32 -arch x86 -consoleLog -console

!ENTRY org.eclipse.debug.ui 4 0 2013-07-10 23:23:08.809
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException: Exception in org.eclipse.debug.internal.ui.DebugUIPlugin.start() of bundle org.eclipse.debug.ui.
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
    at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1177)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: …
Run Code Online (Sandbox Code Playgroud)

osgi eclipse-plugin osgi-bundle

4
推荐指数
2
解决办法
2万
查看次数

包含所有给定元素的最小数量的容器

假设C引用一组容器{c1,c2,c3....cn},其中每个容器包含一组有限的整数{i1,i2,i3...im}.此外,假设整数可能存在于多个容器中.给定一组有限的整数S {s1,s2,s3...sz},找到C包含所有整数的最小子集的大小S.

请注意,可能有数千个容器,每个容器有数百个整数.因此,蛮力很难解决这个问题.

我尝试使用Greedy算法解决问题.也就是说,每次我选择集合中整数最多的容器时S,我都失败了!

有谁能建议这个问题的快速算法?

algorithm semantic-analysis genetic-algorithm

3
推荐指数
1
解决办法
229
查看次数