【发布时间】:2018-05-12 18:02:01
【问题描述】:
我做了一个简单的类来测试天气我是否能够将数据写入我的数据库
package climaxinvoice;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Calendar;
public class InsertValues {
public static void main(String args[]) throws ClassNotFoundException, SQLException
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/cxinvoice.invoice_list","admin","admin");
Calendar cdr = Calendar.getInstance();
java.sql.Date startDate = new java.sql.Date(cdr.getTime().getTime());
String query = " insert into cxinvoice.invoice_list (number, company, date, payment, quantity, subtotal_five, cgst_five, sgst_five, subtotal_twelve, cgst_twelve, sgst_twelve, total, items)" + " value (?,?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement st = conn.prepareStatement(query);
st.setInt(1,1);
st.setString(2,"Climax Exclusive");
st.setDate(3,startDate);
st.setString(4,"CASH");
st.setString(5,"5");
st.setString(6,"1000");
st.setString(7,"250");
st.setString(8,"250");
st.setString(9,"2000");
st.setString(10,"750");
st.setString(11,"750");
st.setString(12,"3000");
st.setString(13,"a|b|c|d");
st.execute();
conn.close();
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
文件运行,但我无法看到我的表格有任何更改 我是 MySQL 新手 附上我的工作台的屏幕截图 workbench output
【问题讨论】:
-
自动提交为假或真。看起来它是假的..你能明确地调用connection.commit(),让我们知道会发生什么吗?应该可以解决这个问题
-
@user641887 它没有帮助
-
您在控制台中看到了什么?
-
没有错误构建成功只是我在我的数据库中看到空表
标签: java mysql prepared-statement mysql-workbench