我正在运行我的程序,但出现此错误:
'[Microsoft][ODBC SQL Server Driver][SQL Server]Disallowed implicit conversion from data type char to data type money, table 'OJT.dbo.Patients', column 'pTotalDue'. Use the CONVERT function to run this query'
我该如何解决?谁能帮我?
这是我的代码:
private void btnInsertActionPerformed(java.awt.event.ActionEvent evt) {
PreparedStatement pstmt = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:OJT_dsn";
String user = "******";
String pass = "******";
String sql = "INSERT INTO dbo.Patients"
+ "(pIDNo,pLName,pFName,pMI,pSex,pStatus,pTelNo,pDocID,pAddr,pStreet,pBarangay,pCity,pProvince,pLnameKIN,pFNameKIN,pMIKIN,pRelationKIN,pTotalDue)"
+ "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
Connection connection = DriverManager.getConnection(url, user, pass);
pstmt = connection.prepareStatement(sql);
pstmt.setString(1, txtPatientID.getText());
pstmt.setString(2, txtpLName.getText());
pstmt.setString(3, txtpFName.getText());
pstmt.setString(4, txtpMI.getText());
pstmt.setString(5, txtSex.getText());
pstmt.setString(6, txtStatus.getText());
pstmt.setString(7, txtpTel.getText());
pstmt.setString(8, txtpDoctor.getText());
pstmt.setString(9, txtStreetNo.getText());
pstmt.setString(10, txtStreetName.getText());
pstmt.setString(11, txtBarangay.getText());
pstmt.setString(12, txtCity.getText());
pstmt.setString(13, txtProvince.getText());
pstmt.setString(14, txtLnameKIN.getText());
pstmt.setString(15, txtFNameKIN.getText());
pstmt.setString(16, txtMIKIN.getText());
pstmt.setString(17, txtRelation.getText());
pstmt.setString(18, txtTotal.getText());
pstmt.executeUpdate();
JOptionPane.showMessageDialog(rootPane, "Patient Added!");
}catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
最佳答案
您应该使用pstmt.setDouble(...);
pstmt.setDouble(18, Double.parseDouble(txtTotal.getText()));
关于java - 在JAVA中转换数据类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15805124/