关于Mysql数据库的注意点

1.注意属性为String的数据在JDBC操作语句中要加单引号

例子:

conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/sounds","root", "root");
stmt = conn.createStatement();

并且UserId是varchar(100)类型。

错误:ResultSet rs = stmt.executeQuery("select * from userinfo where UserId = "+userid+");

正确:ResultSet rs = stmt.executeQuery("select * from userinfo where UserId = '"+userid+"'");

posted @ 2015-10-17 01:16  Deribs4  阅读(215)  评论(0编辑  收藏  举报