不知道是不是是ptmt.execute()的问题

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.JDBC.DBUtil;
import model.Emps;public class EmpsDao {	
public void add(Emps g) throws Exception {	
	Connection conn = DBUtil.getConnection();	
		String sql = ""+"insert into emp(eid,enmae,job,mal,deptno)" + "vlues(?,?,?,?,?)";
		PreparedStatement ptmt = null;	
		try {	
		ptmt = conn.prepareStatement(sql);
	         ptmt.execute(sql);	}catch(SQLException e) {		
	         	e.printStackTrace();		}				
	         	ptmt.setInt(1, g.getEid());
	         					
	         ptmt.setString(2, g.getEname());			
	         	ptmt.setString(3, g.getJob());				
	         	ptmt.setInt(4, g.getMal());				
	         	ptmt.setInt(5, g.getDeptno());				
	         	ptmt.execute();	}		
public void update() {			
}		
public void delect() {			
}		
public List<Emps> query() throws Exception{		
Connection conn = DBUtil.getConnection();	
	Statement stmt = conn.createStatement();	
		ResultSet rs = stmt.executeQuery("select ename,eid from emp");	
					List<Emps> gs = new ArrayList<Emps>();	
			Emps g = null;		
			while(rs.next()) {		
				g = new Emps();		
					g.setEname(rs.getString("ename"));	
							g.setEid(rs.getInt("eid"));
											
							gs.add(g);		}
			return gs;			}		
			public Emps get() {		
			return null;	}
			}
			
			


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 'vlues(?,?,?,?,?)' at line 1

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)

at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)

at com.mysql.jdbc.Connection.execSQL(Connection.java:3206)

at com.mysql.jdbc.Statement.execute(Statement.java:727)

at dao.EmpsDao.add(EmpsDao.java:27)

at action.EmpsAction.main(EmpsAction.java:22)

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 'vlues(1012,'咸鱼哥','文员',1000,20)' at line 1

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)

at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)

at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)

at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:882)

at dao.EmpsDao.add(EmpsDao.java:42)

at action.EmpsAction.main(EmpsAction.java:22)


小小怪下士的荣耀
浏览 3640回答 4
4回答

慕沐9307871

两处错误:values 拼写错误“ptmt.execute(sql);”这句应该去掉

产品经理不是经理

你的sql写错了。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java