📄 databasetest.java
字号:
import java.sql.*;
public class DatabaseTest {
public static void conn() {
Connection con=null;
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","fanson");
System.out.println("ok");
}
catch ( ClassNotFoundException cnfex ) {
System.err.println("装载 JDBC/ODBC 驱动程序失败。" );
cnfex.printStackTrace();
System.exit( 1 );
}
catch ( SQLException sqlex ) {
System.err.println( "无法连接数据库" );
sqlex.printStackTrace();
System.exit( 1 );
}
finally{
if(con!=null){
try{
con.close();
}catch(SQLException e){}
}
}
}
}
///////////////String name = new String(rs.getString(2).getBytes("ISO-8859-1"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -