怎么连接数据库?

wangqing01 2004-09-08 12:42:32
是 SQL server
...全文
143 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
pdw2009 2004-09-08
  • 打赏
  • 举报
回复
连接数据库有4种方式,希望你到CSDN的文中心去看看大哥大姐们整理出的JDBC资料。。。
Frank1982 2004-09-08
  • 打赏
  • 举报
回复
/*
* DBOperation.java
*
* Created on 2004年7月19日, 上午9:52
*/

package Autosale;

import java.sql.*;

/**
*
* @author user
*/
public class DBOperation {

/* jdbc-odbc bridge driver */
private String strDbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
/* odbc data source */
private String strConn = "jdbc:odbc:autosale";
/* connection */
private Connection conn = null;
/* data set */
private ResultSet result = null;
/* PreparedStatement */
//private PreparedStatement pst = null;
/* database user */
private String strUser = "Frank";
/* user password */
private String strPassword = "";

/**
* constructor
*/
public DBOperation() {
try{
Class.forName( strDbDriver );
} catch( ClassNotFoundException ex ) {
System.err.println( ex.getMessage() );
}
}

/**
* constructor
* @param strUser database user
* @param strPassword user password
*/
public DBOperation(String strUser, String strPassword) {
this();
this.strUser = strUser;
this.strPassword = strPassword;
}


/**
* execute query and retrive the data
* @param strSql SQL string( select )
* @return result data
*
* @throws SQLException
*/
public ResultSet executeQuery( String strSql ) throws SQLException {
// clear result set
result = null;

// get Connection
conn = DriverManager.getConnection( strConn, strUser, strPassword );
Statement st = conn.createStatement();

// query
return st.executeQuery( strSql );
}

/**
* modify the data in database
* @param strSql SQL string ( delete, insert and update )
* @return execute result
* -1: error
* other: normal(the count of the data rows modified )
*
* @throws SQLException
*/
public int executeUpdate( String strSql ) throws SQLException {
// return value
int nRetValue = -1;

// get connection
conn = DriverManager.getConnection( strConn, strUser, strPassword );
Statement st = conn.createStatement();

// update
nRetValue = st.executeUpdate( strSql );

// close Statement and Connection
st.close();
conn.close();

return nRetValue;
}


}

这个是使用odbc的
你设置一下桥接就可以了
tyonggang 2004-09-08
  • 打赏
  • 举报
回复
网络上很多的。呵呵。
给你一个参考一下。
package Util;

import java.io.*;
import java.sql.*;
public class DBConn
{

public static Connection GetDBConn()
{
Connection conn=null;
try{
Class.forName("org.gjt.mm.mysql.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/aa","root","");
System.out.println("Connect ok");
}
catch(Exception e)
{
e.printStackTrace();
}
return conn;
}
}
我用的时mysql的驱动,你去下一个,然后放到web-inf/lib目录下
AHUA1001 2004-09-08
  • 打赏
  • 举报
回复
老大,你问的太抽象了。不是想让别人帮你作吧。
一般这样的例子很多书上都有,在网络上也可以搜索到很多的。
内容概要:本文围绕“可再生能源发电与电动汽车的协同调度策略”展开硕士论文级别的研究与复现工作,基于Matlab平台构建了高比例可再生能源接入背景下电力系统与电动汽车(EV)之间的多时间尺度协同优化模型。研究重点在于应对风光发电不确定性,充分利用电动汽车作为移动储能单元的灵活充放电能力(含V2G技术),实现电网削峰填谷、提升新能源消纳效率与系统运行经济性。文中综合考虑了异质电动车集群特性、V2G过程中的损耗约束以及随机因素影响,采用如深度确定性策略梯度(DDPG)强化学习、混合整数线性规划(MILP)等先进优化算法进行求解,并通过基准模型对比验证了所提自适应调度策略在提升电网稳定性、降低运行成本方面的有效性。; 适合人群:具备一定电力系统基础知识、优化理论背景及Matlab编程能力的研究生、科研人员,以及从事新能源并网、智能电网调度、车网互动(V2G)等方向的工程技术人员。; 使用场景及目标:①学习并复现已发表高水平硕士论文中的协同调度建模方法与仿真流程;②掌握将深度强化学习(如DDPG)应用于虚拟电厂、电动汽车集群调度等复杂非线性决策问题的技术路径;③为开展新能源消纳、需求侧响应、微电网优化运行等相关课题的研究提供可复用的代码框架与创新思路参考。; 阅读建议:建议读者结合文中提供的完整Matlab代码与技术文档,深入理解模型构建逻辑、算法实现细节与参数设置依据,优先在Simulink/Matlab环境中运行并调试仿真案例,通过调整场景参数与算法超参,探究不同策略对调度效果的影响,从而深化对协同调度机制与智能优化方法应用的理解。

81,111

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧