
import org.springframework.jdbc.core.RowMapper前面import这个,
/**
* RowMapper的实现类
*
*/
private class AddressRowMapper implements RowMapper<Address>{
public Address mapRow(ResultSet rs, int rownum) throws SQLException {
Address addr = new Address()
addr.setAddrid(rs.getInt("addr_id"))
addr.setReceiveaddr1(rs.getString("receiveaddr1"))
addr.setEprice(rs.getFloat("e_price"))
return addr
}
}
这个是连接数据库表的。
import com.microsoft.sqlserver.jdbc.*
import org.springframework.jdbc.core.*
public class DbService {
public DbService(){
SQLServerDataSource dataSource = new SQLServerDataSource()
dataSource.setURL("jdbc:sqlserver://127.0.0.1:1433DatabaseName=BeCherry")
dataSource.setUser("sa")
dataSource.setPassword("111111")
this.jdbcTemplate = new JdbcTemplate(dataSource)
}
protected JdbcTemplate jdbcTemplate
}
连接整个数据库的java
1、导入.sql文件命令:mysql>use
数据库名mysql>
source
d:/mysql.sql
2、建立数据库:mysql>
create
database
库名
3、建立数据表:mysql>
use
库名mysql>
create
table
表名
(字段名
varchar(20),
字段名
char(1))
4、删除数据库:mysql>
drop
database
库名
5、删除数据表:mysql>
drop
table
表名;
6、将表中记录清空:mysql>
delete
from
表名
7、往表中插入记录:mysql>
insert
into
表名
values
("hyq","m")
8、更新表中数据:mysql->
update
表名
set
字段名1='a',字段名2='b'
where
字段名3='c'
9、用文本方式将数据装入数据表中:mysql>
load
data
local
infile
"d:/mysql.txt"
into
table
表名
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)