java查数据库有哪些表现,用java怎么查询数据库表的各种状态
来源:整理 编辑:黑码技术 2024-08-17 07:12:03
1,用java怎么查询数据库表的各种状态
什么数据库?如果是Oracle,它有很多 系统 视图,有可能查到你想要的。去看看jdbc能通过表的metadata去查看 信息
2,java 怎么检测MySQL表的存在
解决办法:给root用户再添加一个对全部host都有可以访问的权限:mysql -uroot -ppasswdmysql >grant all privileges on *.* to root@"%" identified by "passwd";mysql >flush privileges;------现在再导出试试吧
3,使用java获得判断数据库是否存在
所谓的数据库是否存在 就是java中有个链接的类 try Connection conn= DriverManager.getConnection(url,user,password); } catch (SQLException e) // TODO Auto-generated catch block e.printStackTrace(); } 看看上面的代码 其实就是你说的 数据库不存在怎么办e.printStackTrace();就是处理 你完全可以去掉e.printStackTrace();这句话 自己写一句话作为提示 明白了吗 就是可以用 异常处理的
4,java查询mysql数据库的有什么作用
应该是编码问题,中英文编码转换的问题。mysql中默认字符集的设置有四级:服务器级,数据库级,表级 。最终是字段级 的字符集设置。注意前三种均为默认设置,并不代码你的字段最终会使用这个字符集设置。所以我们建议要用show create table table ; 或show full fields from tablename; 来检查当前表中字段的字符集设置。mysql中关于连接环境的字符集设置有 client端,connection, results 通过这些参数,mysql就知道你的客户端工具用的是什么字符集,结果集应该是什么字符集。这样mysql就会做必要的翻译,一旦这些参数有误,自然会导致字符串在转输过程中的转换错误。基本上99%的乱码由些造成。我在用hibernate做,编码也改了,可是还有问题。最后在hibernate.cfg.xml中配置jdbc:mysql://localhost:3306/online?characterencoding=utf-8就解决了
5,用JAVA如何来查询数据库里面相关的数据
你的意思就是根据id 找数据本身以及他的叶子节点。 假设你的表叫location
rs : ResultSet stmt: Statement
public ResultSet getLocation(int id) {
String sql = "select id, name, pid from location where id = " + id + "or pid = " + id;
rs = stmt.executeQuery(sql);
}看了好一会儿 终于明白你的意思了。
你输入一个查询条件 这个条件只要id或pid任意一个满足条件就能够查询出来。
Java实现很简单就是获取你的查询条件。不在赘述
SQL:select * from 表名 where id = 参数 or pid = 参数用jdbc喽
public static void main(String[] args) {
/*
* 获得配置库的dburl,dbDriver
*/
String dbUrl="jdbc:informix-sqli://localhost:8898/test2:INFORMIXSERVER=onjz1;user=aaa;password=bbb;LANG=en_US";
String dbDriver="com.informix.jdbc.IfxDriver";
String selectSql="select id,name,pid from 表 where id=?";
Connection conn=null;
//Statement ps=null;
int j=0;
try{
DriverManager.registerDriver((Driver)Class.forName(dbDriver).newInstance());
conn=DriverManager.getConnection(dbUrl);
ResultSet rs = stmt.executeQuery(selectSql);
while(rs.next){
//分别拿取值 就好
}
}看你的问法,估计sql语句和jdbc都没有学,没学的话讲的比较麻烦,单纯语句的话
1:select * from 表 where id=1
2:select * from 表 where id= 1 or pid = 1
3:select * from 表 where id= 9 or pid = 9
补充:你鼓楼区那个后面的pid是12(十二)吧~那样没法选
文章TAG:
java查数据库有哪些表现 用java怎么查询数据库表的各种状态