huazi4995
前两天闲着没什么事,顺便拿着本JAVA的书看了看,觉得JAVA还是蛮有意思的,于是学了学.
下面是一些刚入门的小资料,特记下.

package bookstore;
import java.sql.*;
import java.util.Properties;
public class DBConnection {
//获取数据库连接类
public static Connection getConnection() throws SQLException {
try
    
{
    Class.forName(
"oracle.jdbc.driver.OracleDriver");
}

catch (ClassNotFoundException ex)
{
    ex.printStackTrace();
    
return null;
}

Properties sysProps 
= new  Properties();
sysProps.put(
"user""username");            //数据库的用户名
sysProps.put(
"password""password");  //数据库的密码
return DriverManager.getConnection(
"jdbc:oracle:thin:@192.168.176.107:1521:sundun",sysProps);
}


    

    
//////////执行SQL语句//////////
    private Connection con;
    
private Statement sqlStatemen;
   
public  boolean executeSql(String sql) throws java.sql.SQLException
   
{
       con 
= DBConnection.getConnection();
       sqlStatemen
= con.createStatement();
       
try
       
{
           sqlStatemen.execute(sql);
       }

       
catch(Exception e)
       
{
           
return false;
       }

       
return true;

   }

   
////////////////////////
}

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2021-08-16
猜你喜欢
  • 2021-09-13
  • 2022-12-23
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2022-12-23
相关资源
相似解决方案