java查询数据库的数据并显示出来
数据库表tb_Student和tb_Marktb_Stuent的列studentID,student_name,student_Sex,student_Age,stude...
数据库表tb_Student和tb_Mark
tb_Stuent的列studentID,student_name,student_Sex,student_Age,student_Grade
tb_Mark的列
mrkk_ID,mark_Student,mark_Chinese,mark_Math,mark_English,mark_Colligation
如何用一个按钮显示上面的内容,一个界面上显示所有的内容,例如:student_Name:(一个标签)XXX(一个文本框)……用NetBeans做的代码 展开
tb_Stuent的列studentID,student_name,student_Sex,student_Age,student_Grade
tb_Mark的列
mrkk_ID,mark_Student,mark_Chinese,mark_Math,mark_English,mark_Colligation
如何用一个按钮显示上面的内容,一个界面上显示所有的内容,例如:student_Name:(一个标签)XXX(一个文本框)……用NetBeans做的代码 展开
4个回答
展开全部
本人使用的是 Jena-2.5.7 MySQL 5.0 mysql-connector-java-3.1.10 jdk1.6.0_07
源代码:
import java.io.*;
import java.sql.SQLException;
import com.hp.hpl.jena.db.*;
import com.hp.hpl.jena.rdf.model.*;
public class MysqlTest{
public static final String strDriver = "com.mysql.jdbc.Driver"; // path of driver class
public static final String strURL = "jdbc:mysql://localhost/ontodb"; // URL of database
public static final String strUser = "root"; // database user id
public static final String strPassWord = "4408"; // database password
public static final String strDB = "MySQL"; // database type
public static void main(String[] args){
try{
// 创建一个数据库连接
IDBConnection conn = new DBConnection ( strURL, strUser, strPassWord, strDB );
// 加载数据库驱动类,需要处理异常
try
{
Class.forName(strDriver);
}catch(ClassNotFoundException e){
System.out.println("ClassNotFoundException, Driver is not available...");
}
// 使用数据库连接参数创建一个模型制造器
ModelMaker maker = ModelFactory.createModelRDBMaker(conn);
// 创建一个默认模型,命名为 MyOntology
Model defModel = maker.createDefaultModel();
// 准备需要存入数据库的本体文件,建立输入文件流
FileInputStream inputSreamfile = null;
try
{
File file = new File("D:/Person.owl");
inputSreamfile = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("Ontology File is not available...");
}
InputStreamReader in = null;
try
{
in = new InputStreamReader(inputSreamfile, "UTF-8");
} catch (UnsupportedEncodingException e) {
System.out.println("Exceptions occur33...");
e.printStackTrace();
}
// 读取文件
defModel.read(in,null);
// 关闭输入流读取器
try
{
in.close();
} catch (IOException e) {
System.out.println("Exceptions occurclose1...");
e.printStackTrace();
}
// 执行数据转换,将本体数据存入数据库
defModel.commit();
// 关闭数据库连接
try
{
conn.close();
} catch (SQLException e) {
System.out.println("Exceptions occur22...");
e.printStackTrace();
}
}catch(RDFRDBException e){
System.out.println("Exceptions occur...");
}
}
}
输出结果
Tue Dec 30 17:07:06 CST 2008 TRACE:
Tue Dec 30 17:07:06 CST 2008 TRACE:
.....
Tue Dec 30 17:07:06 CST 2008 TRACE:
Tue Dec 30 17:07:06 CST 2008 TRACE:
Exceptions occur...
帮忙解决一下。。。
源代码:
import java.io.*;
import java.sql.SQLException;
import com.hp.hpl.jena.db.*;
import com.hp.hpl.jena.rdf.model.*;
public class MysqlTest{
public static final String strDriver = "com.mysql.jdbc.Driver"; // path of driver class
public static final String strURL = "jdbc:mysql://localhost/ontodb"; // URL of database
public static final String strUser = "root"; // database user id
public static final String strPassWord = "4408"; // database password
public static final String strDB = "MySQL"; // database type
public static void main(String[] args){
try{
// 创建一个数据库连接
IDBConnection conn = new DBConnection ( strURL, strUser, strPassWord, strDB );
// 加载数据库驱动类,需要处理异常
try
{
Class.forName(strDriver);
}catch(ClassNotFoundException e){
System.out.println("ClassNotFoundException, Driver is not available...");
}
// 使用数据库连接参数创建一个模型制造器
ModelMaker maker = ModelFactory.createModelRDBMaker(conn);
// 创建一个默认模型,命名为 MyOntology
Model defModel = maker.createDefaultModel();
// 准备需要存入数据库的本体文件,建立输入文件流
FileInputStream inputSreamfile = null;
try
{
File file = new File("D:/Person.owl");
inputSreamfile = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("Ontology File is not available...");
}
InputStreamReader in = null;
try
{
in = new InputStreamReader(inputSreamfile, "UTF-8");
} catch (UnsupportedEncodingException e) {
System.out.println("Exceptions occur33...");
e.printStackTrace();
}
// 读取文件
defModel.read(in,null);
// 关闭输入流读取器
try
{
in.close();
} catch (IOException e) {
System.out.println("Exceptions occurclose1...");
e.printStackTrace();
}
// 执行数据转换,将本体数据存入数据库
defModel.commit();
// 关闭数据库连接
try
{
conn.close();
} catch (SQLException e) {
System.out.println("Exceptions occur22...");
e.printStackTrace();
}
}catch(RDFRDBException e){
System.out.println("Exceptions occur...");
}
}
}
输出结果
Tue Dec 30 17:07:06 CST 2008 TRACE:
Tue Dec 30 17:07:06 CST 2008 TRACE:
.....
Tue Dec 30 17:07:06 CST 2008 TRACE:
Tue Dec 30 17:07:06 CST 2008 TRACE:
Exceptions occur...
帮忙解决一下。。。
展开全部
本人使用的是
Jena-2.5.7
MySQL
5.0
mysql-connector-java-3.1.10
jdk1.6.0_07
源代码:
import
java.io.*;
import
java.sql.SQLException;
import
com.hp.hpl.jena.db.*;
import
com.hp.hpl.jena.rdf.model.*;
public
class
MysqlTest{
public
static
final
String
strDriver
=
"com.mysql.jdbc.Driver";
//
path
of
driver
class
public
static
final
String
strURL
=
"jdbc:mysql://localhost/ontodb";
//
URL
of
database
public
static
final
String
strUser
=
"root";
//
database
user
id
public
static
final
String
strPassWord
=
"4408";
//
database
password
public
static
final
String
strDB
=
"MySQL";
//
database
type
public
static
void
main(String[]
args){
try{
//
创建一个数据库连接
IDBConnection
conn
=
new
DBConnection
(
strURL,
strUser,
strPassWord,
strDB
);
//
加载数据库驱动类,需要处理异常
try
{
Class.forName(strDriver);
}catch(ClassNotFoundException
e){
System.out.println("ClassNotFoundException,
Driver
is
not
available...");
}
//
使用数据库连接参数创建一个模型制造器
ModelMaker
maker
=
ModelFactory.createModelRDBMaker(conn);
//
创建一个默认模型,命名为
MyOntology
Model
defModel
=
maker.createDefaultModel();
//
准备需要存入数据库的本体文件,建立输入文件流
FileInputStream
inputSreamfile
=
null;
try
{
File
file
=
new
File("D:/Person.owl");
inputSreamfile
=
new
FileInputStream(file);
}
catch
(FileNotFoundException
e)
{
e.printStackTrace();
System.out.println("Ontology
File
is
not
available...");
}
InputStreamReader
in
=
null;
try
{
in
=
new
InputStreamReader(inputSreamfile,
"UTF-8");
}
catch
(UnsupportedEncodingException
e)
{
System.out.println("Exceptions
occur33...");
e.printStackTrace();
}
//
读取文件
defModel.read(in,null);
//
关闭输入流读取器
try
{
in.close();
}
catch
(IOException
e)
{
System.out.println("Exceptions
occurclose1...");
e.printStackTrace();
}
//
执行数据转换,将本体数据存入数据库
defModel.commit();
//
关闭数据库连接
try
{
conn.close();
}
catch
(SQLException
e)
{
System.out.println("Exceptions
occur22...");
e.printStackTrace();
}
}catch(RDFRDBException
e){
System.out.println("Exceptions
occur...");
}
}
}
输出结果
Tue
Dec
30
17:07:06
CST
2008
TRACE:
Tue
Dec
30
17:07:06
CST
2008
TRACE:
.....
Tue
Dec
30
17:07:06
CST
2008
TRACE:
Tue
Dec
30
17:07:06
CST
2008
TRACE:
Exceptions
occur...
帮忙解决一下。。。
Jena-2.5.7
MySQL
5.0
mysql-connector-java-3.1.10
jdk1.6.0_07
源代码:
import
java.io.*;
import
java.sql.SQLException;
import
com.hp.hpl.jena.db.*;
import
com.hp.hpl.jena.rdf.model.*;
public
class
MysqlTest{
public
static
final
String
strDriver
=
"com.mysql.jdbc.Driver";
//
path
of
driver
class
public
static
final
String
strURL
=
"jdbc:mysql://localhost/ontodb";
//
URL
of
database
public
static
final
String
strUser
=
"root";
//
database
user
id
public
static
final
String
strPassWord
=
"4408";
//
database
password
public
static
final
String
strDB
=
"MySQL";
//
database
type
public
static
void
main(String[]
args){
try{
//
创建一个数据库连接
IDBConnection
conn
=
new
DBConnection
(
strURL,
strUser,
strPassWord,
strDB
);
//
加载数据库驱动类,需要处理异常
try
{
Class.forName(strDriver);
}catch(ClassNotFoundException
e){
System.out.println("ClassNotFoundException,
Driver
is
not
available...");
}
//
使用数据库连接参数创建一个模型制造器
ModelMaker
maker
=
ModelFactory.createModelRDBMaker(conn);
//
创建一个默认模型,命名为
MyOntology
Model
defModel
=
maker.createDefaultModel();
//
准备需要存入数据库的本体文件,建立输入文件流
FileInputStream
inputSreamfile
=
null;
try
{
File
file
=
new
File("D:/Person.owl");
inputSreamfile
=
new
FileInputStream(file);
}
catch
(FileNotFoundException
e)
{
e.printStackTrace();
System.out.println("Ontology
File
is
not
available...");
}
InputStreamReader
in
=
null;
try
{
in
=
new
InputStreamReader(inputSreamfile,
"UTF-8");
}
catch
(UnsupportedEncodingException
e)
{
System.out.println("Exceptions
occur33...");
e.printStackTrace();
}
//
读取文件
defModel.read(in,null);
//
关闭输入流读取器
try
{
in.close();
}
catch
(IOException
e)
{
System.out.println("Exceptions
occurclose1...");
e.printStackTrace();
}
//
执行数据转换,将本体数据存入数据库
defModel.commit();
//
关闭数据库连接
try
{
conn.close();
}
catch
(SQLException
e)
{
System.out.println("Exceptions
occur22...");
e.printStackTrace();
}
}catch(RDFRDBException
e){
System.out.println("Exceptions
occur...");
}
}
}
输出结果
Tue
Dec
30
17:07:06
CST
2008
TRACE:
Tue
Dec
30
17:07:06
CST
2008
TRACE:
.....
Tue
Dec
30
17:07:06
CST
2008
TRACE:
Tue
Dec
30
17:07:06
CST
2008
TRACE:
Exceptions
occur...
帮忙解决一下。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
刚刚漏了帐号密码了,现在补上
try {
//这里的是mysql 举例
//加载驱动
class.forname("com.mysql.jdbc.driver");
//创建数据库连接
connection con = drivermanager.getconnection("jdbc:mysql://localhost:3306/test","root","root");
//创建查询 “请求”
preparedstatement ps = con.preparestatement("select * from user");
//返回查询结果
resultset rs = ps.executequery();
//遍历结果
while(rs.next()) {
//假如 user 表中 有个 name 列
system.out.println("name >> "+rs.getstring("name"));
}
//关闭
rs.close();
ps.close();
con.close();
} catch (exception e) {
e.printstacktrace();
}
try {
//这里的是mysql 举例
//加载驱动
class.forname("com.mysql.jdbc.driver");
//创建数据库连接
connection con = drivermanager.getconnection("jdbc:mysql://localhost:3306/test","root","root");
//创建查询 “请求”
preparedstatement ps = con.preparestatement("select * from user");
//返回查询结果
resultset rs = ps.executequery();
//遍历结果
while(rs.next()) {
//假如 user 表中 有个 name 列
system.out.println("name >> "+rs.getstring("name"));
}
//关闭
rs.close();
ps.close();
con.close();
} catch (exception e) {
e.printstacktrace();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我只能说不难。
去找本基础的书好好看看。
去找本基础的书好好看看。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询