java jdbc报SQL语法错误,实在找不到哪里错了!求大神帮忙看下
JAVA代码(首先可以确定数据库和表名都是正确的)importjava.sql.Connection;importjava.sql.DriverManager;impor...
JAVA代码(首先可以确定数据库和表名都是正确的)
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class ConnMysql {
public static void main(String[] args) throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/wordpress", "root", "");
Statement stat = conn.createStatement();
ResultSet result = stat.executeQuery("select * form wp_options");
while(result.next())
{
System.out.println(result.getString(1)+"\t"
+result.getString(2)+"\t"
+result.getString(3)+"\t"
+result.getString(4));
}
}
}
错误提示:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.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 'form wp_options' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
……………………………… 展开
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class ConnMysql {
public static void main(String[] args) throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/wordpress", "root", "");
Statement stat = conn.createStatement();
ResultSet result = stat.executeQuery("select * form wp_options");
while(result.next())
{
System.out.println(result.getString(1)+"\t"
+result.getString(2)+"\t"
+result.getString(3)+"\t"
+result.getString(4));
}
}
}
错误提示:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.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 'form wp_options' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
……………………………… 展开
4个回答
展开全部
把
ResultSet result = stat.executeQuery("select * form wp_options");
改成
ResultSet result = stat.executeQuery("select * from wp_options");
单词打错了
ResultSet result = stat.executeQuery("select * form wp_options");
改成
ResultSet result = stat.executeQuery("select * from wp_options");
单词打错了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把ResultSet result = stat.executeQuery("select * form wp_options");
改为:
ResultSet result = stat.executeQuery("select * from wp_options");
改为:
ResultSet result = stat.executeQuery("select * from wp_options");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select * form wp_options ,应该是 from ,你打成 form了!!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
from
from
from
from
from
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询