数据图java代码,JAVA图
哪位大侠可以帮我写一段java代码!是关于根据数据库里的数据来形成一个动态树形图
这是代码,你可以自己调试一下。
成都创新互联拥有十余年成都网站建设工作经验,为各大企业提供网站制作、成都做网站服务,对于网页设计、PC网站建设(电脑版网站建设)、app软件开发公司、wap网站建设(手机版网站建设)、程序开发、网站优化(SEO优化)、微网站、申请域名等,凭借多年来在互联网的打拼,我们在互联网网站建设行业积累了很多网站制作、网站设计、网络营销经验,集策划、开发、设计、营销、管理等网站化运作于一体,具备承接各种规模类型的网站建设项目的能力。
数据结构如下:
CREATE TABLE dtree (
id int,
pid int,
name varchar(200),
url varchar(200),
title varchar(200),
target varchar(200),
icon varchar(200),
iconopen varchar(200),
opened bit);
为了实现获取数据库变量功能,需要建立一个DTree类,并编译生成CLASS文件,放入\WEB-INF\classes文件夹下。
DTree类代码如下:
package work3;
public class DTree {
private int id;
private int pid;
private String name;
private String url;
private String title;
private String target;
private String icon;
private String iconOpen;
private int opened;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getPid() {
return pid;
}
public void setPid(int pid) {
this.pid = pid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getIconOpen() {
return iconOpen;
}
public void setIconOpen(String iconOpen) {
this.iconOpen = iconOpen;
}
public int getOpened() {
return opened;
}
public void setOpened(int opened) {
this.opened = opened;
}
}
work3.jsp代码如下:
%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%
%@ page import="java.sql.*"%
jsp:useBean id='settree' scope="application" class="work3.DTree" /
!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
""
html
head
meta http-equiv="Content-Type" content="text/html; charset=GB18030"
link rel="StyleSheet" href="dtree.css" type="text/css" /
script type="text/javascript" src="dtree.js"/script
titledTree in MySQL/title
/head
body
h2
Example
/h2
div class="dtree"
p
a href="javascript: d.openAll();"open all/a |
a href="javascript: d.closeAll();"close all/a
/p
script type="text/javascript"
!--
d = new dTree('d');
%
//驱动程序名
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
//数据库用户名
String userName = "sa";
//密码
String userPwd = "1";
//数据库名
String dbName = "master";
//表名
String tableName = "dtree";
//连接字符串
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName="+dbName;
//加载驱动
Class.forName(driverName).newInstance();
//连接数据库
java.sql.Connection conn = DriverManager.getConnection(url,userName,userPwd);
//得到Statement实例
java.sql.Statement statement = conn.createStatement();
//查询数据
String sql = "select * from " + tableName;
//返回结果
java.sql.ResultSet rs = statement.executeQuery(sql);
//获取变量
while (rs.next()) {
settree.setId(rs.getInt(1));
settree.setPid(rs.getInt(2));
settree.setName(rs.getString(3));
settree.setUrl(rs.getString(4));
settree.setTitle(rs.getString(5));
settree.setTarget(rs.getString(6));
settree.setIcon(rs.getString(7));
settree.setIconOpen(rs.getString(8));
settree.setOpened(rs.getInt(9));
if(settree.getPid()==0)
settree.setOpened(1);
%
d.add(%=settree.getId()%,%=settree.getPid()%,'%=settree.getName()%','%=settree.getUrl()%','%=settree.getTitle()%','%=settree.getTarget()%','','',%=settree.getOpened()%);
%
}
%
document.write(d);
//--
/script
/div
/body
/html
Java怎么读取图中的数据,而且不乱码?希望附带代码
不知道你的文件格式,不过你可以可以尝试用io流来读取。下面代码 我试过是可以读取挺多格式文件的,你试下 拷贝过去改下文件路径就行了。
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ReadFile
{
public static void main(String[] args)
{
//文件位置
String filepath = "D:\\test.pub";
/** 一次读取所有内容 */
FileInputStreamReadFile(filepath);
System.out.println("=====================");
/** 以行为单位读取文件,常用于读面向行的格式化文件 */
BufferedReaderReadFile(filepath);
System.out.println("=====================");
/** 以字节为单位读取文件,常用于读二进制文件,如图片、声音、影像等文件。 */
ReadFileByByte(filepath);
System.out.println("\n=====================");
/** 以行为单位读取文件,常用于读面向行的格式化文件 */
InputSteamReaderReadFile(filepath);
System.out.println("\n=====================");
}
private static void InputSteamReaderReadFile(String filepath)
{
try
{
InputStreamReader sr = new InputStreamReader(new FileInputStream(new File(filepath)));
int temp = 0;
while ((temp = sr.read()) != -1)
{
System.out.print((char)temp);
}
sr.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
private static void ReadFileByByte(String filepath)
{
try
{
File file = new File(filepath);
FileInputStream fis = new FileInputStream(file);
int b = 0;
while ((b = fis.read()) != -1)
{
System.out.print((char)b);
}
fis.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
private static void BufferedReaderReadFile(String filepath)
{
try
{
StringBuffer sb = new StringBuffer();
BufferedReader br = new BufferedReader(new FileReader(new File(filepath)));
String readLine = "";
while ((readLine = br.readLine()) != null)
{
sb.append(readLine + "\n");
}
br.close();
System.out.print(sb.toString());
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
private static void FileInputStreamReadFile(String filepath)
{
try
{
File file = new File(filepath);
FileInputStream fis = new FileInputStream(file);
long filelength = file.length();
byte[] bb = new byte[(int)filelength];
fis.read(bb);
fis.close();
System.out.println(new String(bb));
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
不知道你的文件格式,不过你可以可以尝试用io流来读取。下面代码 我试过是可以读取挺多格式文件的,你试下。
求Java的数据库视图相关操作代码
创建视图 CREATE VIEW VIEW_name AS SELECT empno, ename, sal, deptno FROM emp WHERE deptno = 10;
删除视图 drop VIEW VIEW_name
查询视图 SELECT id, name, salary FROM VIEW_name;
网页标题:数据图java代码,JAVA图
分享URL:http://ybzwz.com/article/dscphsg.html