我正在尝试使用带有此类代码的pyodbc执行查询
cursor.execute("SELECT x from y where Name='%s'"%namepar)
Run Code Online (Sandbox Code Playgroud)
该参数可能带有引号,因此需要对其进行转义才能工作,我该怎么办?我尝试通过在namepar中简单地将“”替换为“ \\”,但仍然无法正常工作,我得到了pyodbc.ProgrammingError
我正在使用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 …