Home > database >  MySQL database doesn't work
MySQL database doesn't work

Time:10-17

Open the running code with the idea, every time are com. Mysql. JDBC. Exceptions. Jdbc4. MySQLSyntaxErrorException: Unknown database 'schooldb'
Men who have know how to solve the
Package chapter07;

Import the Java. SQL. *;

Public class InsertJdbc {
Public static void main (String [] args) {
The Connection con=null;
The Statement Statement=null;
The ResultSet rs=null;
Try {
//the load driver
Class.forname (". Com. Mysql. JDBC Driver ");
//set up data connection
Con=DriverManager. GetConnection (" JDBC: mysql://localhost: 3306/schoolDB? UseSSL=false& CharacterEncoding=utf-8,
""Root", "root");
//send the SQL statement
The statement=con. CreateStatement ();
Int result=statement. ExecuteUpdate (" insert into student (name, age) values (' small a, 18), (" small B, 19) ");
//end to return the result and process
If (result> 0 {
System. The out. Println (" insert success ");
} else {
System. The out. Println (" insert failure ");
}
} the catch (Exception e) {
e.printStackTrace();
} the finally {
//close the database connection
Try {
The statement. The close ();
con.close();
} the catch (SQLException e) {
e.printStackTrace();
}
}

}
}

CodePudding user response:

Schooldb this database?
  • Related