【Java开源代码栏目提醒】:网学会员为需要Java开源代码的朋友们搜集整理了ConnMy.java相关资料,希望对各位网友有所帮助!
package db;
import java.sql.*;
public class ConnMy
{
String serverName="localhost";
String dbDriver="com.mysql.jdbc.Driver";
String port="3306";
String dbName="yuanyuan";
String connURL="jdbc:
mysql://"+serverName+":"+port+"/"+dbName;
String user="root";
String password="tianen";
Connection conn=null;
ResultSet rs=null;
public ConnMy()
{
try
{
Class.forName(dbDriver);
}
catch(ClassNotFoundException e)
{
//do nothing
}
try
{
conn=DriverManager.getConnection(connURL,user,pass
word);
}
catch(SQLException ee)
{
//do nothing
}
}
public ResultSet executeQuery(String sql)
{
try
{
Statement st=conn.createStatement();
rs=st.executeQuery(
sql);
}
catch(SQLException ee)
{
//do nothing
}
return rs;
}
public int executeUpdate(String sql)
{
int res=0;
try
{
Statement st=conn.createStatement();
res=st.executeUpdate(sql);
}
catch(SQLException ee)
{
//do nothing
}
return res;
}
public void close()
{
if(rs!=null)
{
try
{
rs.close();
}
catch(SQLException ee)
{
//do nothing
}
}
if(conn!=null)
{
try
{
conn.close();
}
catch(SQLException ee)
{
//do nothing
}
}
}
}