本文介绍了我怎么改变这个,所以我会在任何计算机上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在制作一个学校项目,在家里,当我使用java derby连接数据库时,它在netbeans中运行,但是将它移动到另一台计算机,它不再知道数据库的位置,有人可以指出错误和告诉我如何更正它以便在.jar文件中的文件夹中查找数据库?I'm making a school project, at home it works in netbeans when i connect the database using java derby, but moving it to another computer, it no longer knows where the database is located, Could someone point out the mistake and tell me how to correct it so it will look for the database in a folder in the .jar file?public boolean checkLogin(String username, String password) { //This code will connect the database to the java program Connection myconObj = null; //allows to connect to database Statement mystatObj = null; // create statement (Execute queries) ResultSet myresObj = null; // get result ResultSetMetaData mymeta = null; try { String query = "select * from JACOVANSTRYP.MAINUSERDATA"; myconObj = DriverManager.getConnection("jdbc:derby://localhost:1527/MainUserData", "jacovanstryp", "Password1234"); mystatObj = myconObj.createStatement(); myresObj = mystatObj.executeQuery(query); mymeta = myresObj.getMetaData(); int colomnNo = mymeta.getColumnCount(); while (myresObj.next()) { String dbUsername = myresObj.getString("Username"); String dbPassword = myresObj.getString("Password"); System.out.println(); if (username.equalsIgnoreCase(dbUsername) && password.equals(dbPassword)) { PrintWriter activeUser = new PrintWriter(new FileWriter("activeUser.db")); activeUser.println(dbUsername); activeUser.close(); return true; } } } catch (Exception e) { e.printStackTrace(); } return false; } 我尝试过: 创建数据库的URL位置,它只是说找不到驱动程序What I have tried:Creating a URL location to the database, it just says Driver not foundDriverManager.getConnection("jdbc:derby://Path/To/Jar/Folder/MainUserData", "jacovanstryp", "Password1234");推荐答案myconObj = DriverManager.getConnection("jdbc:derby://192.168.25.36:1527/MainUserData", "jacovanstryp", "Password1234"); 或直接提及服务器名称而不是IPor mention server name directly instead of IP 这篇关于我怎么改变这个,所以我会在任何计算机上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-18 10:34