小编Dan*_*Man的帖子

Pyodbc查询字符串引用转义

我正在尝试使用带有此类代码的pyodbc执行查询

cursor.execute("SELECT x from y where Name='%s'"%namepar)
Run Code Online (Sandbox Code Playgroud)

该参数可能带有引号,因此需要对其进行转义才能工作,我该怎么办?我尝试通过在namepar中简单地将“”替换为“ \\”,但仍然无法正常工作,我得到了pyodbc.ProgrammingError

python string escaping pyodbc

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

Netty 4.0.x正确捕获ConnectException

我正在使用Netty开发一个应用程序,我需要在客户端处理ConnectException,以防万一,例如,连接超时.

这是代码

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;

public class ConnectTest {

public static void main(String[] args) throws Exception {
    Bootstrap b = new Bootstrap();
    b.group(new NioEventLoopGroup()).channel(NioSocketChannel.class)
    .handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {

        }
    });
    final ChannelFuture f = b.connect("0.0.0.0", 8080);
    f.addListener(new FutureListener<Void>() {

        @Override
        public void operationComplete(Future<Void> future) throws Exception {
            if (!f.isSuccess())
                System.out.println("Test Connection failed");
        }
    });
    f.sync();
}
}
Run Code Online (Sandbox Code Playgroud)

这就是结果:

        Test Connection …

java netty connectexception

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

标签 统计

connectexception ×1

escaping ×1

java ×1

netty ×1

pyodbc ×1

python ×1

string ×1