用java连接数据库啊。下面给点例子可以参考,不大好,凑合看
import javasqlConnection;import javasqlDriverManager;
import javasqlPreparedStatement;
import javasqlResultSet;
import javasqlSQLException;
public class JdbcConnection
{
private String driver;
private String dbname;
private String username;
private String password;
private String url;
private Connection con;
private PreparedStatement pstmt;
private ResultSet rs;
public JdbcConnection(){
thisdriver="commicrosoftsqlserverjdbcSQLServerDriver";
thisdbname=数据库名";
thisusername="数据库账号";
thispassword="数据库密码";
thisurl="地址加数据库名";
}
//创建连接方法
public Connection getconnection()
{
try
{
ClassforName(driver);
con=DriverManagergetConnection(url,username,password);
} catch (ClassNotFoundException e)
{
// TODO Auto-generated catch block
eprintStackTrace();
} catch (SQLException e)
{
// TODO Auto-generated catch block
eprintStackTrace();
}
return con;
}
//关闭连接方法
public void coloseConnection(Connection con,ResultSet rs,PreparedStatement pstmt)
{
if(rs!=null)
{
try
{
rsclose();
} catch (SQLException e)
{
eprintStackTrace();
}
}
if(pstmt!=null)
{
try
{
pstmtclose();
} catch (SQLException e)
{
// TODO Auto-generated catch block
eprintStackTrace();
}
}
if(con!=null)
{
try
{
conclose();
} catch (SQLException e)
{
// TODO Auto-generated catch block
eprintStackTrace();
}
}
}
public Connection getCon()
{
return con;
}
public void setCon(Connection con)
{
thiscon = con;
}
public PreparedStatement getPstmt()
{
return pstmt;
}
public void setPstmt(PreparedStatement pstmt)
{
thispstmt = pstmt;
}
public ResultSet getRs()
{
return rs;
}
public void setRs(ResultSet rs)
{
thisrs = rs;
}
public String getDriver()
{
return driver;
}
public void setDriver(String driver)
{
thisdriver = driver;
}
public String getDbname()
{
return dbname;
}
public void setDbname(String dbname)
{
thisdbname = dbname;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
thisusername = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
thispassword = password;
}
public String getUrl()
{
return url;
}
public void setUrl(String url)
{
thisurl = url;
}
}
以上就是关于java怎样存数据到mysql数据库全部的内容,包括:java怎样存数据到mysql数据库、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)