import java.sql.*;
import java.io.*;
public class preparedstatementdemo
{
public static void main(String arg[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:yoksource","","");
String Sqlcmd="insert into yokrecord values(?,?,?)";
** PreparedStatement ps=con.prepareStatement(Sqlcmd);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a name");
ps.setString(1,br.readLine());
System.out.println("Enter age");
ps.setInt(2,Integer.parseInt(br.readLine()));
System.out.println("enter address");
ps.setString(3,br.readLine());
ps.executeUpdate();
System.out.println("inserted");
}
}
**错误:不兼容的类型
答案 0 :(得分:1)
我认为问题在于你使用的实际INSERT
命令 - 语法应该是:
INSERT INTO yokrecord (fieldname1,fieldname2,fieldname3) values(?,?,?);