Home > Back-end >  Why execute executeUpdate directly out of the () statement?
Why execute executeUpdate directly out of the () statement?

Time:09-22


Public static void main (String [] args) {
Try {
//define the database connection driver
Class.forname (" sun. JDBC. Odbc. JdbcOdbcDriver ");
//define the database connection address
String="url: JDBC: odbc driver={Microsoft Access driver (*. MDB)}; DBQ=D://document////bored to death of class sophomore ()//Java//Dat//Dat1 MDB ".//JDBC,//the String url="JDBC: odbc: redsun";//ODBC
//use the DriverManager class getConnection () method to establish connection
The Connection con=DriverManager. GetConnection (url, ""," ");
//by using the method of connection con create Statement object, in order to execute an SQL query
//use the Statement interface, add a record (success)

The Statement stmt1=con. CreateStatement ();
String num="001";
String nam="zhang SAN";
Int total=200;
Int business=90;
String sql1="insert into Candidate values ('" + num + "', '" + nam +"', '" + total + "', '" + business + ") ";
System. The out. Println (sql1);
Stmt1. ExecuteUpdate (sql1);
Stmt1. Close ();
Con. The close ();
ShowData ();
}
The catch (Exception e) {}
}

CodePudding user response:

Jump out is what meaning, jump straight to catch it, to see if the console error prompt

CodePudding user response:



When I was debugging, in to perform executeUpdate () statement directly to catch when I was there, the console and no prompt error

CodePudding user response:

Catch it to print error messages ah e.p rintStackTrace (); And you catch this not self-deception

CodePudding user response:

add out

CodePudding user response:

What data does not match ah
This is my watch:

CodePudding user response:

Look at the data in a database table type and the type of data in the code

CodePudding user response:

Get rid of the single quotes shouldn't add single quotation marks
  • Related