嗨,我一直在尝试通过 java 将字符串插入到 sqlite 数据库中。但是我在 values sql 语句中传递的字符串参数在其中包含引号作为内容。我在想这是我得到的错误,为什么它没有插入数据库。有没有办法绕过插入语句中的引号。谢谢你。
这是代码:
public void addNote(String topicadd, String contentadd) throws Exception
{
try
{
getConnection();
statement = conn.createStatement();
statement.executeUpdate("insert into tbl_notes (notes_topic, notes_content) values ('" + topicadd + "', '" + contentadd +"')");
System.out.println("inserted note");
}
catch (Exception m)
{`enter code here`
System.out.println("error insert topic");
System.out.println(m.getMessage());
}
}
这是参数类型很长......这都在 contentadd
import java.sql.*;
Resultset rset = null; (this has no new ResultSet() initialization)
Connection conn = null; (this has no new initialization too...)
Statement statement = null; (this has now new initialization)
always.....
try
{
}
catch (Exception e) <- can switch e for any other alphabet
{
e.getMessage();
System.out.println("error this module"); <- personal practice
throw e;
}
- getting connection
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite:m.db");
*** this is sqlite connection format 'm.db' is the database name
establish connection first..
statement syntax follows:
statement = conn.createStatement();
rset = statement.executeQuery("select * from tbl_notes");
- executeQuery is used for SELECT sql statements
rset = statement.executeUpdate("insert into tbl_notes (ID, status) values
('100', 'status here');
整个文本都在字符串 contentadd 中,我正在制作一个简短的笔记程序...嗯,它不执行插入语句...在命令提示符附近(文本中的单词)附近出现错误...我' m 使用 sqlite ...如果您需要更多详细信息,请告诉我。再次感谢你。