\t\tJava中System.getProperty的使用方法

参考附录1-4,选择数据库新建一个表,新建程序可以访问、插入、更新这个表。(注意,附录2-4没有将数据库访问信息直接写在程序,而是将信息写在同一个工程的 properties 文件)附录1 JdbcTest . java import java . io .*; import java . sql .*; import java . util . Properties ; import java . util . ArrayList ; public class JdbcTest { private Properties props ; private String url ; private String user ; private String passwd ; public JdbcTest (){ testJdbc (); try { jbInit (); catch ( Exception ex ){ ex . printStackTrace (); public static void main ( String [] args ){ JdbcTest jdbctest = new JdbcTest (); public void testJdbc (){ try { props = new Properties (); props . load ( new FilelnputStream (" jdbc . properties ")); url = props . getProperty (" url "); user = props . getProperty (" user "); passwd = props . getProperty (" password "); Class . forName ( props . getProperty (" driver ")); Connection conn = DriverManager . getConnection ( url , user , passwd ); Statement stmt = conn . createStatement (); ResultSet result = stmt . executeQuery (" SELECT * FROM authors "); while ( result . next ()){ System . out . println ("\ n System . out . print ( result . getString (" au _ fname ")+"( t "); System . out . print ( result . getString (" city "')+"\( t "); System . out . print ( result . getString (" address ")+"( t "); --'"'); System . out . println (); stmt . executeUpdate (" update authors set state =' cn ' where au _ id ='172-32-1176';''); stmt . executeUpdate (" insert into authors ( au _ id , au _ Iname , au _ fname , contract ) values ('123-45-6789',' hello ',' good ',0);''); stmt . executeUpdate (" insert into authors ( au _ id , au _ Iname , au _ fname , contract ) values ('000-00-0000',' hello ',' good ',0);''); stmt . executeUpdate (" delete from authors where au _ id ='123-45-6789';,'; result = stmt . executeQuery (" SELECT * FROM authors au _ id ='000-00-0000'""); if ( result . next ()){ System . out . printin ("\ n - System . out . print ( result . getString (" au _ fname ")+"( t "); System . out . print ( result . getString (" city ")+"\( t "); System . out . print ( result . getString (" address ")+"( t "); System . out . printin (); stmt . close (); conn . close (); where ---"); catch ( Exception e ){ e . printStackTrace (); private void jbInit () throws Exception {
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值