我想计算ms访问表中的行数"测试"并将它分配给变量" i" .right现在我能够从查询变量中打印我表中的计数行数。我想参与变量" i"。我的第二个问题是,要计算的sql语句是否正确,我应该使用任何其他查询而不是那个?
package amogh.java;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
public class readCSVnew1 {
public static void main(String[] args) throws IOException {
// // read 2.txt
// create token1
String token1 = "";
// create Scanner inFile1
Scanner inFile1 = new Scanner(new File("D:\\Warface Launcher\\eclipse is fk\\something\\src\\2.txt")).useDelimiter(" ");
// ArrayList
// List<String> temps = new LinkedList<String>();
List<String> temps = new ArrayList<String>();
// while loop
while (inFile1.hasNext()) {
// find next line
token1 = inFile1.next();
temps.add(token1);
}
inFile1.close();
int i;
int count = 1;
String[] tempsArray = temps.toArray(new String[0]);
for (String s : tempsArray) {
System.out.println(s);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:testing");
PreparedStatement ps = con.prepareStatement("insert into testing (ID,fileName)values(?,?)");
ps.setInt(1,count);
ps.setString(2,s);
String query ="SELECT * COUNT(ID) FROM testing";
System.out.println(query);
System.out.println(s);
System.out.println("inserted");
count++;
ps.executeUpdate();
con.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}
}
答案 0 :(得分:0)
你的查询语法错误必须是:
SELECT COUNT(*) FROM testing
您永远不会在代码中执行此select
查询。