JDBC 程序错误! 谁帮我看下谢谢!!
importjava.sql.*;publicclassTest1{publicstaticvoidmain(String[]agrs){Connectionconn;P...
import java.sql.*;
public class Test1 {
public static void main(String[] agrs) {
Connection conn;
PreparedStatement pstate;
//ResultSet result;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/mydata", "root", "root");
pstate = conn.prepareStatement("insert into ? values(?, ?)");
pstate.setString(1, "land");
pstate.setString(2, "kobe24");
pstate.setString(3, "8402175110");
pstate.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
}
}
运行后报下面错误:
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 ''land' values('kobe24', '8402175110')' at line 1
就是往某个表插入一条数据 但是这个表不确定 我就用一个问好代替 难道不行么! 怎么改? 展开
public class Test1 {
public static void main(String[] agrs) {
Connection conn;
PreparedStatement pstate;
//ResultSet result;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/mydata", "root", "root");
pstate = conn.prepareStatement("insert into ? values(?, ?)");
pstate.setString(1, "land");
pstate.setString(2, "kobe24");
pstate.setString(3, "8402175110");
pstate.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
}
}
运行后报下面错误:
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 ''land' values('kobe24', '8402175110')' at line 1
就是往某个表插入一条数据 但是这个表不确定 我就用一个问好代替 难道不行么! 怎么改? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询