这个代码是从mysql的jdbc的doc里摘下来的:

import java.sql.*;

public class TestMySqlConnection {
public static void main(String[] args){
try {
Class.forName(
"com.mysql.jdbc.Driver").newInstance();
}
catch (Exception ex) {
ex.printStackTrace();
}
Connection conn
= null;
try {
conn
=
DriverManager.getConnection(
"jdbc:mysql://localhost/test?" +
"user=monty&password=greatsqldb");

}
catch (SQLException ex) {
System.out.println(
"SQLException: " + ex.getMessage());
System.out.println(
"SQLState: " + ex.getSQLState());
System.out.println(
"VendorError: " + ex.getErrorCode());
}
}

}

 

相关文章:

  • 2021-08-30
  • 2022-12-23
  • 2022-01-07
猜你喜欢
  • 2022-01-07
  • 2021-12-06
  • 2022-01-24
  • 2021-06-01
  • 2022-01-07
  • 2022-12-23
相关资源
相似解决方案