I am working on a Java application which has a built in HTTP server, at the moment the server is implemented using ServerSocketChannel, it listens on port 1694 for requests:
msvrCh = ServerSocketChannel.open();
msvrCh.socket().bind(new InetSocketAddress(mintPort));
msvrCh.configureBlocking(false);
Run Code Online (Sandbox Code Playgroud)
A thread is installed to manage requests and responses:
Thread thrd = new Thread(msgReceiver);
thrd.setUncaughtExceptionHandler(exceptionHandler);
thrd.start();
Run Code Online (Sandbox Code Playgroud)
The thread is quite simple:
Runnable msgReceiver = new Runnable() {
@Override
public void run() {
try{
while( !Thread.interrupted() ) {
//Sleep a short period between checks for …Run Code Online (Sandbox Code Playgroud) 我试图找出为什么我无法连接到笔记本电脑上的mariadb.MariaDB安装了几个数据库,我可以使用HeidiSQL连接而没有问题.
我正在尝试将Java应用程序连接到数据库,但我得到:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mysql
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
Run Code Online (Sandbox Code Playgroud)
我已经下载了"mariadb-java-client-1.2.2.jar"并将其添加到项目中.
我的数据库URI是:
jdbc:mysql://localhost:3306/mysql
Run Code Online (Sandbox Code Playgroud)
我试过改变使用方法:
jdbc:mariadb://localhost:3306/mysql
Run Code Online (Sandbox Code Playgroud)
结果相同.我之前在另一台PC上工作过,但我不知道它为什么不在笔记本电脑上工作?用户名和密码正确,与用于连接HeidiSQL的用户名和密码相同.
我试过两个:
Class.forName("com.mysql.jdbc.Driver");
Run Code Online (Sandbox Code Playgroud)
和
Class.forName("org.mariadb.jdbc.Driver");
Run Code Online (Sandbox Code Playgroud)
注册图书馆然后我读到这些不是必需的....我错过了什么?
码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class clsDB {
//The name of this class
private static final String TAG = clsDB.class.toString();
//Define database URL, user name and password
private static final String SERVER_ADDR = "localhost";
//The database address on Windows development system
private static final String DB_URL = …Run Code Online (Sandbox Code Playgroud) 是否有Java中的内置例程将百分比转换为数字,例如,如果字符串包含100%或100px或100,我想要一个包含100的浮点数.
使用Float.parseInt或Float.valueOf会导致异常.我可以编写一个解析字符串并返回数字的例程,但我问这个已经存在了吗?
我想计算任何给定行和列的索引(基数为0),其中行和列为基数1且列数已知,例如2
如果max_columns为2且index为5,则从索引计算行号:
Row = (index % max_columns) + (int)(index / max_columns)
= (5 % 2) + (int)(5 / 2)
= 1 + 2
= 3
Run Code Online (Sandbox Code Playgroud)
从索引计算列号
Col = max_columns - (index % max_columns)
= 2 - (5 % 2)
= 2 - 1
= 1
Run Code Online (Sandbox Code Playgroud)
问题是如何从索引为0的索引计算行和列.这是为了计算java应用程序中数组的索引.
由'Willem Van Onsem'提供给我的正确解决方案
其中Row为3,Col为2,max_columns为2:
Index = (Row * max_columns) + Col - max_columns - 1
= (3 * 2) + 2 - 2 - 1
= 6 + (-1)
= 5
Run Code Online (Sandbox Code Playgroud) 替换它的正确方法是什么:
std::ostringstream buf;
std::for_each(bd.begin(), bd.end(), buf << boost::lambda::constant(" ") << boost::lambda::_1);
Run Code Online (Sandbox Code Playgroud)
使用不使用 boost 的实现?这是我尝试过的:
std::string backspace("&nbps;");
std::ostringstream buf;
std::for_each(bd.begin(), bd.end(), buf << backspace << std::placeholders::_1);
Run Code Online (Sandbox Code Playgroud)
第二个 '<<' 用红色下划线表示,我收到错误消息:
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::_Ph<1>' (or there is no acceptable conversion)
Run Code Online (Sandbox Code Playgroud) 我有一个'QString'包含"-3.5",但是如果我尝试使用'toInt'方法将其转换为整数,则返回0.为什么?
QString strTest = "-3.5";
int intTest = strTest.toInt();
qDebug() << intTest;
Run Code Online (Sandbox Code Playgroud)
intTest将为0?
我想确保对象正确分层,我在网上读到实现这一点的方法是设置 z-index 样式。
但是到目前为止我还没有能够做到这一点,我想以编程方式设置样式。
我试过了:
pobjWidget->setStyleSheet("z-index: 5");
Run Code Online (Sandbox Code Playgroud)
和
pobjWidget->setStyleSheet("z: 5");
Run Code Online (Sandbox Code Playgroud)
这两者都会导致控制台中显示“未知属性 z-index”或“未知属性 z”。
pobjWidget 是一个指向 QWidget 的指针。
我需要这个的原因是我正在将具有透明背景的小部件渲染到实时视频小部件上,并且我需要确保顶部的小部件不闪烁,这是为了照亮闪烁。
我正在开发一个使用 boost 1.61 的 C++ 项目,我正在用 std 调用替换 boost,是否有 boost::this_thread::interruption_point() 的替代方法?
我有很多信号都具有相同的参数但执行不同的功能.
所有信号的连接和断开代码都是相同的,信号连接的插槽处理程序也是如此.
而不是一遍又一遍地编写这段代码.我想使用函数指针或类似的东西来分配信号,然后有一个公共代码块来执行连接或断开连接.
以下代码仅用于说明我所描述的内容,它无效且无法编译.
void (*pfnSignal)(quint8, QString);
switch( eSigID ) {
case SIGNAL_A:
pfnSignal = signalA;
break;
case SIGNAL_B:
pfnSignal = signalB;
break;
default:
pfnSignal = NULL;
}
if ( pfnSignal != NULL ) {
QObject::connect(pobjRef, pfnSignal, this, SLOT(handler(quint8, QString)));
}
Run Code Online (Sandbox Code Playgroud) 我编写了一个带有两个参数的 VBA 函数,第一个是字符串,第二个是范围,在工作表中指定为:
=strPack(B1,G3)
Run Code Online (Sandbox Code Playgroud)
在代码中,该例程声明为:
Public Function strPack(ByVal strHex As String, ByRef rngCnt As Range) As String
On Error Goto ErrHandler
If False Then
ErrHandler:
MsgBox Err.Description
Exit Function
End If
Dim intCnt As Integer
intCnt = 0
'...do something with strHex and increment intCnt whilst we go
rngCnt.Value = CStr(intCnt)
'strPack is populated by the body of the function
strPack = "Hello World"
End Function
Run Code Online (Sandbox Code Playgroud)
我尝试过 .Value、.Value2 和 .Text,都导致错误:
Application-defined or object-defined error
Run Code Online (Sandbox Code Playgroud)
当我查看调试器时,strHex 和 rngCnt 都是有效且正确的。为什么我无法分配范围以及如何修复它?
错误处理程序不是问题所在,请尝试一下,它工作得非常好,并且是在发生错误时拾取错误并中止函数的标准方法。
[编辑]我刚刚尝试了以下操作: …