请教SSIS连接PostgreSQL数据库的方法
答案:1 悬赏:0 手机版
解决时间 2021-11-12 01:00
- 提问者网友:世勋超人
- 2021-11-11 05:36
请教SSIS连接PostgreSQL数据库的方法
最佳答案
- 五星知识达人网友:独钓一江月
- 2021-11-11 06:11
import java.sql.*;
public class connect
{
String strDBDriver="org.postgresql.Driver";
String strDBUrl="jdbc:postgresql://localhost:1433;databasename=数据库名;
private Connection conn=null;
private Statement stmt=null;
ResultSet rs=null;
public ksxt()
{
try
{
Class.forName(strDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("ksxt():"+e.getMessage());
}
}
public ResultSet executeQuery(String sql)
{
rs=null;
try
{
conn=DriverManager.getConnection(strDBUrl,"数据库登录名","密码");
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql)
{
stmt=null;
rs=null;
try
{
conn=DriverManager.getConnection(strDBUrl,"数据库登录名","密码");
stmt=conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
}
catch(SQLException ex)
{
System.err.println("aq.executeQuery:"+ex.getMessage());
}
}
public void closeStmt()
{
try
{
stmt.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public void closeConn()
{
try
{
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
public class connect
{
String strDBDriver="org.postgresql.Driver";
String strDBUrl="jdbc:postgresql://localhost:1433;databasename=数据库名;
private Connection conn=null;
private Statement stmt=null;
ResultSet rs=null;
public ksxt()
{
try
{
Class.forName(strDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("ksxt():"+e.getMessage());
}
}
public ResultSet executeQuery(String sql)
{
rs=null;
try
{
conn=DriverManager.getConnection(strDBUrl,"数据库登录名","密码");
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql)
{
stmt=null;
rs=null;
try
{
conn=DriverManager.getConnection(strDBUrl,"数据库登录名","密码");
stmt=conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
}
catch(SQLException ex)
{
System.err.println("aq.executeQuery:"+ex.getMessage());
}
}
public void closeStmt()
{
try
{
stmt.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public void closeConn()
{
try
{
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯