这听起来有点奇怪,但我想PreparedStatement
在拥有Statement
. 这是因为我的项目几乎是 50% ,直到现在我已经使用了Statement
.
在我的 Database 类中,我有一个构造函数,每次我需要使用 Mysql 服务器时连接到 mysql :
public class Database
{
private Statement m_statement = null;
private Connection m_connection = null;
private PreparedStatement m_prepared = null; // that one was added just now
private static final String ACCOUNTS_TABLE = "CheckingAccountsTable";
private static final String PERSONNEL_TABLE = "PersonnelTable";
// private static final String
public Database() throws ClassNotFoundException
{
try
{
Class.forName("com.mysql.jdbc.Driver");
this.m_connection = DriverManager.getConnection("jdbc:mysql://localhost","root","root");
this.m_statement = this.m_connection.createStatement();
}
catch (SQLException s)
{
System.out.println("SQL statement is not executed! 2!");
}
}
}
// from here I have something like 20 methods that are based on the Statement
改变一切将需要很多我没有的时间。所以,我的问题是:
我可以使用我创建的语句PreparedStatement
吗?或创建 PreparedStatement
基于Statement
?
谢谢