我试图准确地了解Java的服务提供程序机制如何工作以找到适当的JDBC驱动程序.这是我到目前为止:
由于Class.ForName不再用于显式加载JDBC Driver,因此Java会从传递给getConnection方法的数据库url字符串中知道它需要什么类型的驱动程序.例如,连接到oracle数据库的数据库url将是这样的:
public static final String DB_URL = "jdbc:oracle:thin@//localhost:1521/ORCL";
Run Code Online (Sandbox Code Playgroud)
然后,DriverManager将在projects类路径中指定的jar中查找oracle驱动程序的实现.它会在META-INF/Services每个jar的目录中查找驱动程序配置文件(其中将是实际驱动程序类的名称).在Class Loader将加载它找到的第一个比赛而忽略其他.
以上工作准确吗?如果我错过了什么或者出了什么问题,请告诉我.
如何在我的Java SWT应用程序中右键对齐复选框?这是我的代码片段:
Button checkFullECR = new Button(scrolledForm.getBody(), SWT.CHECK);
checkFullECR.setAlignment(SWT.RIGHT);
checkFullECR.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
checkFullECR.setText("I need the complete ECR/ECN Process:");
Run Code Online (Sandbox Code Playgroud)
它看起来如下:
[ ] I need the complete ECR/ECN Process:
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像:
I need the complete ECR/ECN Process: [ ]
Run Code Online (Sandbox Code Playgroud) 我有一个带按钮的片段,单击该按钮应该更改我应用程序中的主题,但是当我打开该类时,我只会收到此错误:这是 logcat
08-14 21:32:45.914 29624-29624/addid E/AndroidRuntime? FATAL EXCEPTION: main
Process: appid, PID: 29624
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at appid.Fragment.GuidaTv.InitView(GuidaTv.java:75)
at appid.Fragment.GuidaTv.onCreateView(GuidaTv.java:41)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Run Code Online (Sandbox Code Playgroud)
我的课:
public class GuidaTv extends Fragment implements View.OnClickListener{
private Button FirstThemButton;
private Button SecondThemButton;
private Button ThirdThemButton;
private SharedPreferences sharePrefences;
private …Run Code Online (Sandbox Code Playgroud) 我使用a ExecutorService有多个线程将文本写入文件,但我无法设法同步run()方法,而不是正确的逐行字符串我问,我有一个字符串的所有字符的混合,因为他们写它同时.
import java.io.BufferedReader
...
class WriteDns implements Runnable {
File file;
String text;
WriteDns(File file, String text) {
this.file = file;
this.text = text;
}
public void run() {
synchronized (this) {
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(file)))) {
bw.write(turnDns() + "\n");
} catch (IOException e) {
System.out.println("Error");
}
}
}
public String turnDns() {
int space = text.indexOf(' ');
String ip = text.substring(0, space);
String theRest = text.substring(space);
String temp = ip; …Run Code Online (Sandbox Code Playgroud)