2013-11-15
展开全部
1、从DB得到图片路径
2、载入图片到 ImageIcon
3、显示在JLabel中,setIcon(ImageIcon)
2、载入图片到 ImageIcon
3、显示在JLabel中,setIcon(ImageIcon)
展开全部
try{
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动
String URL = "jdbc:sqlserver://localhost:1433; DatabaseName=MCNumber"; //连接服务器和数据库test
String userName = "sa"; //默认用户名
String userPwd = "sa"; //密码
Connection Conn;
Class.forName(driverName).newInstance();
Conn = DriverManager.getConnection(URL, userName, userPwd);
String Image ="select markLinkUrl from MCNumber M " +
"join StoreImage S on M.MCNumber = S.MCNumber where M.MCNumber="+ImageIng;
PreparedStatement ps=Conn.prepareStatement(Image);//执行sql语句的容器
ResultSet rs=ps.executeQuery();
while(rs.next())
{
String url = rs.getString("markLinkUrl"); //数据库中存储地址的列名
Icon icon = new ImageIcon(url);
ImageLabel = new JButton(icon);
PanelNeed.add(ImageLabel);
}
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动
String URL = "jdbc:sqlserver://localhost:1433; DatabaseName=MCNumber"; //连接服务器和数据库test
String userName = "sa"; //默认用户名
String userPwd = "sa"; //密码
Connection Conn;
Class.forName(driverName).newInstance();
Conn = DriverManager.getConnection(URL, userName, userPwd);
String Image ="select markLinkUrl from MCNumber M " +
"join StoreImage S on M.MCNumber = S.MCNumber where M.MCNumber="+ImageIng;
PreparedStatement ps=Conn.prepareStatement(Image);//执行sql语句的容器
ResultSet rs=ps.executeQuery();
while(rs.next())
{
String url = rs.getString("markLinkUrl"); //数据库中存储地址的列名
Icon icon = new ImageIcon(url);
ImageLabel = new JButton(icon);
PanelNeed.add(ImageLabel);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询