當前位置:首頁 > IT技術(shù) > 數(shù)據(jù)庫 > 正文

1.5 java連接gbase數(shù)據(jù)庫
2021-09-14 16:30:35

package com.jdbclearn.gbase8a.dataload;

import java.sql.*;
?
public class TestConnection {
public static void main(String args[]) {
try {
String user = "test";
String passwd = "test123";
?
Connection connect = DriverManager.getConnection(url, user, passwd);
// 連接URL為 jdbc:gbase//服務(wù)器地址/數(shù)據(jù)庫名 ,后面的2個參數(shù)分別是登 陸用戶名和密碼
//testdb 數(shù)據(jù)庫實例
?
System.out.println("Success connect Gbase 8a server!");
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery("select * from test");
// user 為你表的名稱
while (rs.next()) {
System.out.println(rs.getString("name"));
}
} catch (Exception e) {
System.out.print("get data error!");
e.printStackTrace();
}
}
}
?
gbase-connector-java-8.3.81.53-build54.1-bin.jar
?

?
?
package com.jdbclearn.gbase8a.dataload;
?
?
import java.sql.*;
?
?
public class TestConnection {
public static void main(String args[]) {
?
?
try {
//gbase.url=jdbc:gbase://127.0.0.1
String user = "testuser";
String passwd = "**********";
?
?
Connection connect = DriverManager.getConnection(url, user, passwd);
// 連接URL為 jdbc:gbase//服務(wù)器地址/數(shù)據(jù)庫名 ,后面的2個參數(shù)分別是登陸用戶名和密碼
?
?
System.out.println("Success connect Gbase 8a server!");
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery("select * from T1");
// user 為你表的名稱
while (rs.next()) {
System.out.println(rs.getString("name"));
}
} catch (Exception e) {
System.out.print("get data error!");
e.printStackTrace();
}
}
}
?
?
?
?
?

本文摘自 :https://www.cnblogs.com/

開通會員,享受整站包年服務(wù)立即開通 >