jsp 连接数据库
package com.db;
import java.sql.*;
public class Connect{
String userName="root";
String userPassword="";
String url="jdbc:mysql://localhost:3306/stu?useUnicode=true&characterEncoding=gb2312";
Connection conn;
String errorMessage;
public Connect(){
errorMessage="";
conn=null;
}
public Connection getConn()
{
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection(url,userName,userPassword);
}catch(Exception e)
{
conn=null;
errorMessage=e.toString();
}
return conn;
}
public String getErrorMessage()
{
return errorMessage;
}
}