java.sql.SQLNonTransientConnectionException
:java.net.ConnectException
:错误连接到端口1527上的服务器localhost,并显示消息Connection refused:connect。
我正在使用Netbeans。如果我转到服务选项卡并右键单击Java DB并启动Server,它可以正常工作。
如何在运行时以编程方式执行此操作?我只需要任何方法来启动Java DB Server。
public class login extends javax.swing.JFrame {
public void close() {
WindowEvent close = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(close);
}
public login() {
try {
initComponents();
((JLabel) jComboBox1.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
Calendar currentdate = new GregorianCalendar();
int year1 = currentdate.get(Calendar.YEAR);
for (int i = 2000; i <= year1; i++) {
jComboBox1.insertItemAt(i, jComboBox1.getItemCount());
}
NetworkServerControl server = new NetworkServerControl();
server.start(null);
} catch (Exception ex) {
Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
}
} private void loginbtnActionPerformed(java.awt.event.ActionEvent evt) {
try {
String url = "jdbc:derby://localhost:1527/PreSchool";
String user = "admin1";
String pass = "admin1";
Connection con = DriverManager.getConnection(url, user, pass);
Statement stat = con.createStatement();
String query = "SELECT * FROM admin1.login WHERE username ='" + usertxt.getText() + "'";
ResultSet rs = stat.executeQuery(query);
while (rs.next()) {
if ((usertxt.getText().equalsIgnoreCase(rs.getString("username"))) && (passtxt.getText().equalsIgnoreCase(rs.getString("password")))) {
switch (rs.getString("department")) {
case "0": {
manager man = new manager();
man.setVisible(true);
break;
}
case "1": {
program pr = new program();
pr.setVisible(true);
break;
}
}
}
}
close();
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.toString());
}
}
这是derby.log:
An exception was thrown during network server startup. org.apache.derby.impl.drda.NetworkServerControlImpl.<init>(java.lang.String, java.lang.String)
java.security.PrivilegedActionException: java.lang.NoSuchMethodException: org.apache.derby.impl.drda.NetworkServerControlImpl.<init>(java.lang.String, java.lang.String)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.derby.iapi.jdbc.DRDAServerStarter.boot(Unknown Source)
at org.apache.derby.impl.drda.NetworkServerControlImpl.start(Unknown Source)
at org.apache.derby.drda.NetworkServerControl.start(Unknown Source)
at login.<init>(login.java:33)
at login$3.run(login.java:231)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.NoSuchMethodException: org.apache.derby.impl.drda.NetworkServerControlImpl.<init>(java.lang.String, java.lang.String)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at org.apache.derby.iapi.jdbc.DRDAServerStarter$1.run(Unknown Source)
... 20 more