插入错误: 列名或所提供值的数目与表定义不匹配。SQLException: 代码如下,望高手指正,大榭!! 10
classbeifen{beifen(){}voidBF(){StringdriverName="com.microsoft.sqlserver.jdbc.SQLServ...
class beifen {
beifen(){}
void BF(){
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url="jdbc:sqlserver://localhost:1433;DatabaseName=tongxunlu";
String user="sa";
String password="123";
Connection conn=null;
Statement stmt=null;
Statement pstm=null;
try{
Class.forName(driverName);
conn=DriverManager.getConnection(url,user,password);
stmt=conn.createStatement();
System.out.println("连接成功"+conn.getMetaData().getURL());
}
catch (SQLException se) {
se.printStackTrace();
}
catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
String command;
try{
command="CREATE TABLE nobbbba(姓名 char(20),电话 char(20),邮件 char(30))";
pstm=conn.createStatement();
pstm.executeUpdate(command);
System.out.println("建表成功!");
BufferedReader in=new BufferedReader(new FileReader("mytxl.txt"));
while(in.readLine()!=null){
String line=in.readLine();
command="INSERT INTO nobbbba VALUES("+line+")";
pstm.executeUpdate(command);
}
System.out.println("备份成功!");
}catch(SQLException ex){
System.out.println("SQLException:");
while(ex!=null){
System.err.println(ex.getMessage());
ex=ex.getNextException();
}
}catch(IOException ex){
System.out.println("IOException:");
System.out.println(ex.getMessage());
}
}
}
注:
mytxl.txt文件的格式,我试过很多种,都是同样的错误提示。 展开
beifen(){}
void BF(){
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url="jdbc:sqlserver://localhost:1433;DatabaseName=tongxunlu";
String user="sa";
String password="123";
Connection conn=null;
Statement stmt=null;
Statement pstm=null;
try{
Class.forName(driverName);
conn=DriverManager.getConnection(url,user,password);
stmt=conn.createStatement();
System.out.println("连接成功"+conn.getMetaData().getURL());
}
catch (SQLException se) {
se.printStackTrace();
}
catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
String command;
try{
command="CREATE TABLE nobbbba(姓名 char(20),电话 char(20),邮件 char(30))";
pstm=conn.createStatement();
pstm.executeUpdate(command);
System.out.println("建表成功!");
BufferedReader in=new BufferedReader(new FileReader("mytxl.txt"));
while(in.readLine()!=null){
String line=in.readLine();
command="INSERT INTO nobbbba VALUES("+line+")";
pstm.executeUpdate(command);
}
System.out.println("备份成功!");
}catch(SQLException ex){
System.out.println("SQLException:");
while(ex!=null){
System.err.println(ex.getMessage());
ex=ex.getNextException();
}
}catch(IOException ex){
System.out.println("IOException:");
System.out.println(ex.getMessage());
}
}
}
注:
mytxl.txt文件的格式,我试过很多种,都是同样的错误提示。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询