
正文
pg数据库url pg数据库配置参数
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如何使用Blob数据类型在Postgres-database
我大概明白了,估计是这个意思,就是客户给你一个URL,这个URL指定一个资源,有可能是图片或者视频,需要把这个资源以BLOB的方式存进数据库里面。
其实这应该是两个步骤,先或者这个资源的HTTP连接,然后存进数据库里面。下面这个DEMO(下载JavaEye的logo放进我的数据库),你参考一下,可能对你有帮助。
Java代码
public static void main(String[] args) throws Exception {
URL url = new URL("");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.connect();
InputStream in = conn.getInputStream();
saveBlob(in,in.available());
in.close();
}
static void saveBlob(InputStream in,int len) throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123");
PreparedStatement ps = conn.prepareStatement("insert into user_table(id,name,photo) values(?,?,?)");
ps.setInt(1, 100);
ps.setString(2, "testUser1");
ps.setBinaryStream(3, in,len);
int rst = ps.executeUpdate();
System.out.println("insert rst = "+rst);//1就代表正确了
ps.close();
conn.close();
}
相关问答
Q1: 106.75.84.24/pg/html1 是什么网址?
1.它是一个没有域名的网站,直接使用ip进行访问
2.服务器ip地址106.75.84.24
1)如果url没有重写解释为:pg目录下有一个html1目录,里面有一个默认文件名(如果语言为php,则为index.pho或者index.html)
2)如果url重写,则指向重写目录下的默认文件名。重写目录具体看怎么重写的
3.跳转到2345主页原因可能是http协议头重定向或者js重定向。指向2345主要是为了推广。此类网站最好少打开,因为可能会挂木马病毒进行传播获利。
Q2: 用java怎么写URL接口
在java中,调用http请求接口,主要通过流的方式进行调用,示例接口如下:
/**
* 程序中访问http数据接口
*/
public String searchLoginService(String urlStr) {
/** 网络的url地址 */
URL url = null;
/** http连接 */
HttpURLConnection httpConn = null;
/**//** 输入流 */
BufferedReader in = null;
StringBuffer sb = new StringBuffer();
try{
url = new URL(urlStr);
in = new BufferedReader( new InputStreamReader(url.openStream(),"UTF-8") );
String str = null;
while((str = in.readLine()) != null) {
sb.append( str );
}
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
} finally{
try{
if(in!=null) {
in.close();
}
}catch(IOException ex) {
logger.error(ex.getMessage(), ex);
}
}
String result =sb.toString();
System.out.println(result);
return result;
}
Q3: pg库batch怎么看
Statement和PreparedStatement都支持批处理操作,这里我们只说明PreparedStatement的批处理方式:
方法:
void addBatch()
将要执行的SQL先保存起来,先不执行
这个方法需要在在设置完所有的占位符之后调用
int[] executeBatch()
这个方法用来执行SQL语句,这个方法会将批处理中所有SQL语句执行
我们需要在mysql的url地址中加入一下参数:
rewriteBatchedStatements=true
例如:URL = "jdbc:mysql://127.0.0.1:3306/test?rewriteBatchedStatements=true";
Q4: 如何使用drupal直接操作postgres数据库?
Drupal是主流的CMS系统之一。因此具备Drupal技能的开发人员有很多。
考虑这样的情况,如果你有一个现有的非Drupal系统,然后有一个Drupal开发团队,你希望这个Drupal团队帮你扩展应用。
那么这个时候,Drupal应用就应该设计成是支持多数据库的。
在Drupal中使用多数据,也很简单。
1、首先在配置文件(Settings.php)中把默认的数据库配置项改成数组形式:
?php
$db_url['default'] = 'mysql://drupal:drupal@localhost/drupal';
$db_url['jigo'] = 'mysql://user:pwd@localhost/jigo';
?
注意这里的数据库格式必须是一样的。即不能一个是mysql,另外一个是pgsql。
而且默认的必须是drupal自己的数据库。
2、然后在程序中动态切换:
?php
global $db_url; // 数据库链接的内部变量
if (!is_array($db_url)) {
$default_db = $db_url;
$db_url = array('default' = $default_db);
}
//也可以动态设置新的数据库,这里注释掉,因为我们已经写在配置项中
//$db_url['jigo'] = 'mysql://user:pwd@localhost/jigo';
db_set_active('jigo'); // activation execution same as explained above
$results = db_query($sql); //sql represents the query to be executed
db_set_active('default'); // set back to original
?
regards,
iefreer
Q5: java怎么样通过jdbc连接postgre数据库
Class.forName("org.postgresql.Driver").newInstance();
String url ="jdbc:postgresql:5432//localhost/harddisk"
//myDB为数据库名
String user="myuser";
String password="mypassword";
Connection conn= DriverManager.getConnection(url,user,password);
关于pg数据库url和pg数据库配置参数的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







