Netbeans MySQL连接 - 与jbdc无关(Netbeans MySQL Connection - not to do with jbdc)
我有一个登录应用程序,需要连接到服务器以检查用户名和密码。 我正在使用netbeans并安装了jbdc并在服务选项卡中工作(感谢堆栈溢出!)。 通过jbdc工作我的意思是我可以通过它执行SQL脚本。
我已经使用MS Server 16和MySQL进行了设置,所以我确信这是代码:
连接方式:
package dbUtil; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class dbConnection { private static final String USERNAME = "root"; private static final String PASSWORD = "mess"; private static final String SQCONN = "jdbc:mysql://localhost:1434/MessyLogin?zeroDateTimeBehavior=convertToNull"; public static Connection getConnection()throws SQLException{ try { Class.forName("com.mysql.jdbc.Driver"); return DriverManager.getConnection(SQCONN, USERNAME, PASSWORD); }catch (ClassNotFoundException e) { } return null; } }
loginmodel:
package LogIn; import dbUtil.dbConnection; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.logging.Level; import java.util.logging.Logger; public class LogInModel { Connection connection; public LogInModel() { try{ this.connection = dbConnection.getConnection(); }catch(SQLException e){ } if(this.connection == null){ System.out.println("here"); // System.exit(1); } } public boolean isDatabaseConnected(){ return this.connection != null; } public boolean isLogin(String username, String password) throws Exception{ PreparedStatement pr = null; ResultSet rs = null; String sql = "SELECT * FROM MessyLogin where username = ? and Password = ?"; try{ pr = this.connection.prepareStatement(sql); pr.setString(1, username); pr.setString(2, password); rs = pr.executeQuery(); boolean bool1; if(rs.next()){ return true; } return false; } catch(SQLException ex){ return false; } finally { { pr.close(); rs.close(); } } } }
我相信问题是
return null;
来自dbConnection文件。if(this.connection==Null)
返回true并且系统正在退出。先谢谢你。
I have a login app that needs to connect to a server to check the username and password. I am using netbeans and the jbdc is installed and working in the services tab(thanks stack overflow!). By the jbdc is work I mean that i can execute SQL script through it.
I have set this up with MS Server 16 and MySQL so I am convied it is the code:
Connection method:
package dbUtil; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class dbConnection { private static final String USERNAME = "root"; private static final String PASSWORD = "mess"; private static final String SQCONN = "jdbc:mysql://localhost:1434/MessyLogin?zeroDateTimeBehavior=convertToNull"; public static Connection getConnection()throws SQLException{ try { Class.forName("com.mysql.jdbc.Driver"); return DriverManager.getConnection(SQCONN, USERNAME, PASSWORD); }catch (ClassNotFoundException e) { } return null; } }
loginmodel:
package LogIn; import dbUtil.dbConnection; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.logging.Level; import java.util.logging.Logger; public class LogInModel { Connection connection; public LogInModel() { try{ this.connection = dbConnection.getConnection(); }catch(SQLException e){ } if(this.connection == null){ System.out.println("here"); // System.exit(1); } } public boolean isDatabaseConnected(){ return this.connection != null; } public boolean isLogin(String username, String password) throws Exception{ PreparedStatement pr = null; ResultSet rs = null; String sql = "SELECT * FROM MessyLogin where username = ? and Password = ?"; try{ pr = this.connection.prepareStatement(sql); pr.setString(1, username); pr.setString(2, password); rs = pr.executeQuery(); boolean bool1; if(rs.next()){ return true; } return false; } catch(SQLException ex){ return false; } finally { { pr.close(); rs.close(); } } } }
I believe the issue is the
return null;
from the dbConnection file. Theif(this.connection==Null)
comes back true and the system is exiting.Thank you in advance.
原文:https://stackoverflow.com/questions/45916622
最满意答案
在这里查看维基百科上的这篇文章。 你有多种选择,你的陈述可以是真的但也是假的。 这也是关于udacity Ai课程的,他们刚刚把它放在一个单独的类别,部分已知。 它仍然比未知更好,但你必须使用别的东西。
Take a look at this article on wikipedia here. You have multiple choice there, you statement can be true but also false. This was also on udacity Ai course and they have just put it in a separate category, partially known. It is still better than unknown but you'll have to use something else.
相关问答
更多-
java编程,人工智能:怎么编写“谓词演算”程序呢?[2019-02-23]
能够使用计算机表达的算法,就是可以转换为数学语言来描述。谓词演算其实就是将事物归类,具体的说就是将A和B两个事物的共同点进行归纳,并下一个数学定义来描述这个共同点。如果下一个输入的事物如C,就对C进行判断,看C是否符合A和B的共同点,如果是则C与A和B同属于这一类。 如一个简单的一元谓词: 定义1:树都有树叶。 定义2:A是树; 定义3:B与A是同一类植物; 则可知B是树并且有树叶。 其实谓词演算就是对于数学包含关系的判断。 如果体现在编程中,就是变量的对比,转换,替换和传递等。 -
总之,是的。 从技术上讲,Pi演算可能会编码诸如高阶响应式编程之类的东西(因为您可以动态创建并将通道作为第一类值传递)。 在肤浅的层面上,都试图用事件来描述一个系统,而不是状态。 这是产生“基于事件的系统”领域的重要区别。 Pi演算非常普遍,很有可能您在反应式编程环境中构建的任何东西都可能具有与pi演算术语相同的合理编码。 In short, yes. Technically the Pi-calculus could probably encode something like higher-order ...
-
如果您想使用任何功能性编程语言进行编程 ,这一点至关重要。 我的意思是,了解图灵机有多有用? 那么,如果你写C,语言范例与图灵机器非常接近 - 你有一个指令指针和一个当前指令,并且机器在当前状态下采取一些动作,然后沿着下一条指令行走。 在一种功能性的语言中,你根本不能这样想 - 这不是语言范式。 你必须考虑到lambda演算,以及如何评估术语。 如果您不知道lambda演算,您将更难以在功能语言中有效。 If you want to program in any functional programming ...
-
Prolog-Farmer Wolf Goat Cabbage中的谓词微积分(Predicate Calculus in Prolog-Farmer Wolf Goat Cabbage)[2022-05-19]
谓词move/2采用表单state/4 in参数以实现问题状态。 在州,第一个参数用于农民,第二个用于狼,第三个用于山羊,第四个用于卷心菜。 状态的每个参数变量应该得到值e(对于东)或w(对于西)。 为了解决这个问题,你可以定义表格move(state(F1,W1,G1,C1),state(F2,W2,G2,C2)):-...子句move(state(F1,W1,G1,C1),state(F2,W2,G2,C2)):-...类似于图片中的子句。 当农民和狼都在同一侧时,使用图中所示的谓词,因此在输入状态下, ... -
谓词演算,暗示(predicate calculus , implication)[2023-06-16]
在这里查看维基百科上的这篇文章。 你有多种选择,你的陈述可以是真的但也是假的。 这也是关于udacity Ai课程的,他们刚刚把它放在一个单独的类别,部分已知。 它仍然比未知更好,但你必须使用别的东西。 Take a look at this article on wikipedia here. You have multiple choice there, you statement can be true but also false. This was also on udacity Ai cours ... -
实现组合演算(Implementing the combinator calculus)[2022-01-18]
你需要分两步进行。 模式匹配器将模式与树相匹配,并将模式中的字典映射变量构建为树中的值。 然后,通过用字典中的值替换变量,将该字典传递给填充替换项的单独函数。 SICP中描述的模式匹配方法在C中可以很好地工作,尽管您可能会发现使用可变数据结构更容易。 请参阅https://mitpress.mit.edu/sicp/full-text/sicp/book/node99.html You need to take it in two separate steps. A pattern matcher matc ... -
如何在元组关系演算中实现sql“where in not”?(How to implement sql “where not in” in tuple relational calculus?)[2022-05-17]
你的查询与我的朋友的内部查询相同,因为你说f2是不在f1中的东西而f1是不在f东西而且所有这些都有一个来源frequents而且它意味着f2=f并且你的查询返回这个: select f.bar,f.drinker from frequents f,serves s,likes l where l.beer=s.beer and f.bar=s.bar and f.drinker=l.drinker; 但我认为这个查询可以给你更好的结果我的朋友: select f.bar,f.drinker from f ... -
使用与逻辑语法完全无关的其他符号(例如,传统上由C宏使用的#)并不是更清晰。 只要您使用Prolog的术语语法,对于horn子句的字面类比就无法工作,因为前缀运算符和后缀运算符都表示相同的术语。 空头的条款是:- p. 一个空体的子句是p :- . 适当的运算符都表示术语:-(p). 由于您可以动态更改运算符,因此可以使用:-(p). 因此是非常模糊的:它可能表示一个空头的事实或规则。 在Prolog文本中,读取术语:-(Dir). 被称为指令 。 这是自爱丁堡Prolog以来,自1977年以来。最初(并且 ...
-
如何减少lambda演算(How to reduce lambda calculus)[2023-01-23]
我冒昧地将它重写为haskell语法 (\y -> x (\x-> x y)) (\y -> x (\x-> x y)) t x (\x -> x t) 因为y已经绑定到输入\ y所有y都将被t替换。 编辑:如下面的评论中所述,如果包含空闲x的位置,则将此范围中的绑定x重命名为“新”名称非常重要。 这个名字目前没有任何意义。 如果我们说 let t = \t -> x t 然后适当的替换看起来像 x (\z -> z (\t -> x t)) 在pigworker所述的情况下, pigworker一 ... -
您应该尝试为谓词找到更清晰的名称。 即使你知道sub_third应该是什么意思,我们也不知道。 这使得理解和调整代码变得更加困难。 你使用select/3基本想法是好的,但你还没有正确地分解问题。 首先尝试计算列表之间的差异,然后检查它不包含任何不需要的元素的额外属性: % list_subtract(Xs, Ys, Zs) is true if Zs is a list obtained by removing one % occurrence of each element of Ys from Zs. ...