我無法將數據從utf8文件中保存到我的SQL Server 2008表中 - SQL排序規則= SQL_Latin1_General_CP1_CI_AS - (當我執行我的System.out.print插入語句:重音是確定的)。Java:將UTF-8文件中的數據保存到Sql Server 2008中
這裏是我做的步驟:
1)將文件轉換爲字符串:
File f = new File(file);
byte[] buffer = new byte[(int) f.length()];
in = new DataInputStream(new FileInputStream(f));
in.readFully(buffer);
result = new String(buffer);
2)執行INSERT:
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Properties properties = new Properties();
properties.put("charSet", "ISO-8859-1");
properties.put("user", user);
properties.put("password", password);
connection = DriverManager.getConnection("jdbc:jtds:sqlserver://" + serverName + ":1433;DatabaseName=" + dbName + "", properties);
statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
statement.executeUpdate(sqlInsert, Statement.RETURN_GENERATED_KEYS);
感謝您的幫助
非常感謝您!有效。 – Remy