作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 itext 中开发一个项目,当我尝试从数据库获取数据并使用 itext 将其填充到已经存在的 pdf 中时,我收到此错误“不支持定位更新。
package itext.sample;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;
/**
* @author prithvi
*
*/
public class FirstPdf {
private static final String Result = "D:/Eclipse Java/image.pdf";
public static void main(String[] args) throws SQLException,IOException,DocumentException {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your MySQL JDBC Driver?");
e.printStackTrace();
return;
}
System.out.println("MySQL JDBC Driver Registered!");
Connection connection = null;
try {
connection = DriverManager
.getConnection("jdbc:mysql://69.167.139.172/bluedb",
"color", "prithvi");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
if (connection != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
try {
Statement stm = null;
stm = connection.createStatement();//creating database query
ResultSet rs = null;
rs = stm.executeQuery("SELECT * FROM Sec1");
PdfReader reader = new PdfReader("D:/Eclipse Java/HiltonForms2014_r.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(Result));
AcroFields form = stamper.getAcroFields();
form.setField("LASTNAME", rs.getCursorName());
stamper.setFormFlattening(true);
stamper.close();
reader.close();
connection.close();
}
catch (DocumentException | SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
最佳答案
您的数据库不支持getCursorName()
,因此会引发数据库访问错误。
查看您的代码,很难理解为什么需要该方法。您正在获取名为 Sec1
的表的所有字段,并且想要获取带有名称的 String
。
假设具有该名称的字段名为lastname
,则您可以像这样获取该字段的值:
String lastname = null;
if (rs != null)
lastname = rs.getString("lastname");
您现在可以使用姓氏
来填写字段:
form.setField("LASTNAME", lastname);
显然只有您知道“lastname”
是否是数据库中该字段的名称。如果字段名为 "last_name"
、"lname"
或任何其他名称,则此示例将不起作用。
关于java - 从 getCursorName 函数读取数据时出现异常 "positioned update not supported",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31972803/
我正在 itext 中开发一个项目,当我尝试从数据库获取数据并使用 itext 将其填充到已经存在的 pdf 中时,我收到此错误“不支持定位更新。 package itext.sample; impo
我是一名优秀的程序员,十分优秀!