ijidea内使用各种数据库
一、mysql:
jdbc:mysql://localhost:3306?useSSL=false&serverTimezone=GMT%2B8
DataSource数据库连接
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName("com.mysql.cj.jdbc.Driver");
ds.setUrl("jdbc:mysql://localhost:3306/dataname?useSSL=false&serverTimezone=UTC");
ds.setUsername("root");
ds.setPassword("passeord");
JdbcTemplate jt = new JdbcTemplate();
jt.setDataSource(ds);
jt.execute("insert into account(name,money) values ('lll',1000)");
使用xml配置连接数据库
在bean.xml中:
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/basename?serverTimezone=UTC"></property>
<property name="username" value="root"></property>
<property name="password" value="password"></property>
</bean>
在.java程序中:
ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
JdbcTemplate jt = ac.getBean("jdbcTemplate", JdbcTemplate.class);
jt.execute("insert into account(name,money) values ('eee',2000)");
二、 derby
jdbc:derby://localhost:1527/mydb;create=true