以下是我的程序
import java.sql.*;
public class testDBMS { /**
* @param args
*/
public static void main(String[] args) throws ClassNotFoundException,
SQLException{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("111111111");
String str=new String("0404210081");
// 链接并验证数据库
Connection connection = DriverManager
.getConnection("jdbc:mysql://localhost/gongyuguanli","root","0404210081");
System.out.println("22222222222");
Statement state=connection.createStatement();
ResultSet result=state.executeQuery("select xingbie,name from xueshengmingdan"+
"where xuehao ='"+str+"'");
while (result.next())
System.out.println(result.getString(1)+" "+result.getString(2)); }}
运行是抛出异常如下:
111111111
22222222222
Exception in thread "main" com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '='0404210081'' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3243)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3172)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1197)
at testDBMS.main(testDBMS.java:17)
请问是为什么啊 ????我搞了一个植物都不行。
import java.sql.*;
public class testDBMS { /**
* @param args
*/
public static void main(String[] args) throws ClassNotFoundException,
SQLException{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("111111111");
String str=new String("0404210081");
// 链接并验证数据库
Connection connection = DriverManager
.getConnection("jdbc:mysql://localhost/gongyuguanli","root","0404210081");
System.out.println("22222222222");
Statement state=connection.createStatement();
ResultSet result=state.executeQuery("select xingbie,name from xueshengmingdan"+
"where xuehao ='"+str+"'");
while (result.next())
System.out.println(result.getString(1)+" "+result.getString(2)); }}
运行是抛出异常如下:
111111111
22222222222
Exception in thread "main" com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '='0404210081'' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3243)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3172)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1197)
at testDBMS.main(testDBMS.java:17)
请问是为什么啊 ????我搞了一个植物都不行。
解决方案 »
- equals()的问题
- 如何声明一个常量数组?
- 两百分 那位大哥帮我完成一下的啊!!
- Exception in thread "main" java.lang.NoClassDefFoundError: javax/jms/JMSException怎么办
- 百分求购一个登陆模块--要求有MD5加密和验证码
- java里有什么方法可以向任意指定的IP发数据包
- 求助各位大大们 一个算法题
- 请教Java连接mysql数据库的问题,谢谢!
- 在linux中怎么显示中文文件和文件名。我已经安装了简体中文。
- 请问怎么才能把tomcat 3.2做成NT服务?
- swt designer的time类如何使用????
- Java有没有类似于大富翁离线论坛那样的东东
ResultSet result=state.executeQuery("select xingbie,name from xueshengmingdan" + "where xuehao ='"+str+"'");SQL语句拼起来是select xingbie,name from xueshengmingdanwhere xuehao ='学号'是xueshengmingdan和where之间少个空格。上述语句可以改成:ResultSet result=state.executeQuery("select xingbie,name from xueshengmingdan where xuehao ='"+str+"'");这样就可以了。