java的solo的简单介绍

博主:adminadmin 2023-01-17 03:24:05 384

今天给各位分享java的solo的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

急求:java编程问题

采用JDBC技术,我给你一个Demo

//以下是DAO

package com.dao.impl;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.List;

import com.qld.dao.db.Jdbc;

import com.qld.dao.dto.OrderItemBean;

import com.qld.dao.inf.OrderItemDAO;

/**

* 定义了对订单条目表的操作

* @author Administrator

*

*/

public class OrderItemAction implements OrderItemDAO{

/**

* 根据订单号删除订单条目.

*

* @param nid

* 订单条目编号 (-1:表无此条件).

* @param norderid

* 订单号 (-1:表无此条件).

* @return 是否删除成功.

*/

public boolean deleteOrderItem(int nid, int norderid) {

Connection connection = Jdbc.getConnection();

PreparedStatement prepStat=null;

StringBuffer sql=new StringBuffer();

sql.append("delete t_order_detail where 1=1");

try {

if(nid!=-1){

sql.append(" and nid="+nid);

}

if(norderid!=-1){

sql.append(" and norderid="+norderid);

}

prepStat=connection.prepareStatement(String.valueOf(sql));

prepStat.executeUpdate();

} catch (SQLException e) {

try {

connection.rollback();

} catch (SQLException e1) {

// TODO 自动生成 catch 块

e1.printStackTrace();

}

return false;

}finally {

Jdbc.close(prepStat);

Jdbc.close(connection);

}

return true;

}

/**

* 获取订单条目总数.

*

* @return 订单条目总数.

*/

public int getCount() {

Connection connection=Jdbc.getConnection();

PreparedStatement prepStat=null;

String sql="select MAX(nid) from t_order_detail";

ResultSet infoRs = null;

try {

prepStat=connection.prepareStatement(sql);

infoRs = prepStat.executeQuery();

while (infoRs.next()) {

return Integer.valueOf(infoRs.getString(1))+1;

}

} catch (SQLException e) {

try {

connection.rollback();

} catch (SQLException e1) {

// TODO 自动生成 catch 块

e1.printStackTrace();

}

return -1;

} finally {

Jdbc.close(prepStat);

Jdbc.close(connection);

}

return 0;

}

/**

* 获取订单条目总数.

*

* @param norderid

* 订单号.

* @return 订单条目总数.

*/

public int getCount(int norderid) {

Connection connection=Jdbc.getConnection();

PreparedStatement prepStat=null;

String sql="select select seq_t_order_detail.nextval from t_order_detail where norderid=?";

ResultSet infoRs = null;

try {

prepStat=connection.prepareStatement(sql);

prepStat.setInt(1, norderid);

infoRs = prepStat.executeQuery();

while (infoRs.next()) {

return Integer.valueOf(infoRs.getString(1));

}

} catch (SQLException e) {

try {

connection.rollback();

} catch (SQLException e1) {

// TODO 自动生成 catch 块

e1.printStackTrace();

}

return -1;

} finally {

Jdbc.close(prepStat);

Jdbc.close(connection);

}

return 0;

}

/**

* 添加订单条目.

*

* @param orderItemBean

* 订单条目对象.

* @return 添加是否成功.

*/

public boolean insertOrderItem(OrderItemBean orderItemBean) {

Connection connection=Jdbc.getConnection();

PreparedStatement prepStat=null;

String sql="insert into t_order_detail(nid,norderid,nmcid,smcname,sdpn," +

"ncount,nprice,ntotalprice)"

+"values(?,?,?,?,?,?,?,?)";

try {

prepStat=connection.prepareStatement(sql);

prepStat.setInt(1,getCount());

prepStat.setInt(2, Integer.valueOf(orderItemBean.getNorderid()));

prepStat.setInt(3,Integer.valueOf(orderItemBean.getNmcid()));

prepStat.setString(4, orderItemBean.getSmcname());

prepStat.setString(5, orderItemBean.getSdpn());

prepStat.setInt(6, Integer.valueOf(orderItemBean.getNcount()));

prepStat.setInt(7, Integer.valueOf(orderItemBean.getNprice()));

prepStat.setDouble(8, Double.valueOf(orderItemBean.getNtotalprice()));

prepStat.executeUpdate();

return true;

} catch (SQLException e) {

try {

connection.rollback();

} catch (SQLException e1) {

// TODO 自动生成 catch 块

e1.printStackTrace();

}

return false;

} finally {

Jdbc.close(prepStat);

Jdbc.close(connection);

}

}

/**

* 根据订单号查询所有订单条目.

*

* @param norderid

* 订单号.

* @return 订单条目集.

*/

public List searchOrderItem(int norderid) {

ListOrderItemBean orderItemList=new ArrayListOrderItemBean();

String sql="select * from t_order_detail where norderid=? order by nmcid ASC";

Connection connection = Jdbc.getConnection();

ResultSet infoRs = null;

PreparedStatement prepStat = null;

try {

prepStat = connection.prepareStatement(sql.toString());

prepStat.setInt(1,norderid);

infoRs = prepStat.executeQuery();

while (infoRs.next()) {

OrderItemBean orderItemBean=new OrderItemBean();

orderItemBean.setNid(infoRs.getString(1));

orderItemBean.setNorderid(infoRs.getString(2));

orderItemBean.setNmcid(infoRs.getString(3));

orderItemBean.setSmcname(infoRs.getString(4));

orderItemBean.setSdpn(infoRs.getString(5));

orderItemBean.setNcount(infoRs.getString(6));

orderItemBean.setNprice(infoRs.getString(7));

orderItemBean.setNtotalprice(infoRs.getString(8));

orderItemList.add(orderItemBean);

}

} catch (SQLException e) {

try {

connection.rollback();

} catch (SQLException e1) {

// TODO 自动生成 catch 块

e1.printStackTrace();

}

} finally {

Jdbc.close(prepStat);

Jdbc.close(connection);

}

return orderItemList;

}

}

//以下是JDBC获取连接等方法

package com.qld.dao.db;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.naming.NamingException;

import javax.sql.DataSource;

/**

* 该类定义了用于对oracle数据库连接的方法

* @author solo

*

*/

public class Jdbc {

/**

* 返回一个连接

* @return Connection

*/

public static Connection getConnection() {

Connection connection=null;

Context context;

try {

context = new InitialContext();

DataSource ds= (DataSource)context.lookup("java:comp/env/jdbc/tcpdb1");//通过JNDI名得到数据源.

connection = ds.getConnection();//获取连接对象.

} catch (NamingException e) {

// TODO 自动生成 catch 块

e.printStackTrace();

} //容器上下文初始化.

catch (SQLException e) {

// TODO 自动生成 catch 块

e.printStackTrace();

}

return connection;

}

/**

* 关闭传入的连接

* @param connection 要关闭的连接

*/

public static void close(Connection connection) {

try {

connection.close();

} catch (SQLException e) {

e.printStackTrace();

}

}

/**

* 关闭结果集Statement

* @param stat 要关闭的结果集

*/

public static void close(Statement stat) {

try {

stat.close();

} catch (SQLException e) {

}

}

/**

* 关闭结果集PreparedStatement

* @param prepStat 要关闭的结果集

*/

public static void close(ResultSet prepStat) {

try {

prepStat.close();

} catch (SQLException e) {

}

}

}

Java程序(请高手指教)

楼主,你忘记贴图片了

你看下要的是我发的这个效果吗

修改后的代码如下:

import javax.swing.*;

import java.awt.*;

public class work6_1 {

public static void main(String[] args){

try{   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

}  catch(Exception e){}

new solo();

}

}

class solo extends JPanel{

static final int WEIGHT=300;

static final int HEIGHT=200;

private void add(JPanel jp,Component c,GridBagConstraints constraints,int x,int y, int w,int h){

constraints.gridx=x;

constraints.gridy=y;

constraints.gridwidth=w;

constraints.gridheight=h;

jp.add(c,constraints);

}

solo(){

JFrame frame=new JFrame("面板综合测试窗口");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(WEIGHT,HEIGHT);

frame.setVisible(true);

JTabbedPane tp=new JTabbedPane();

frame.setContentPane(tp);

JPanel panel1=new JPanel();

tp.add("panel1", panel1);

tp.setEnabledAt(0, true);

tp.setTitleAt(0, "基本信息");

//JPanel panel2=new JPanel();

//frame.add(this);

panel1.setLayout(new GridBagLayout());

JLabel label1=new JLabel("姓名");

JTextField nameinput=new JTextField(10);

JLabel label2=new JLabel("性别");

JTextField sexinput=new JTextField(10);

JLabel label3=new JLabel("年龄");

JTextField ageinput=new JTextField(10);

JLabel label4=new JLabel("出生年月");

JTextField birthinput=new JTextField(10);

JLabel label5=new JLabel("家庭地址");

JTextField addressinput=new JTextField(10);

GridBagLayout lay=new GridBagLayout();

setLayout(lay);

GridBagConstraints constraints=new GridBagConstraints();

constraints.fill=GridBagConstraints.NONE;

constraints.anchor=GridBagConstraints.CENTER;

constraints.weightx=10;  constraints.weighty=5;

add(panel1,label1,constraints,1,0,1,1);

add(panel1,nameinput,constraints,3,0,4,1);

add(panel1,label2,constraints,1,1,1,1);

add(panel1,sexinput,constraints,3,1,4,1);

add(panel1,label3,constraints,1,2,1,1);

add(panel1,ageinput,constraints,3,2,4,1);

add(panel1,label4,constraints,1,3,1,1);

add(panel1,birthinput,constraints,3,3,4,1);

add(panel1,label5,constraints,1,4,1,1);

add(panel1,addressinput,constraints,3,4,4,1);

}

}

你的代码里有几个问题 造成原来生成的frame和预想的不一样

首先你要搞清楚你要把那些JLabel和JTextFields固件放在哪里

是放在solo里面呢 还是放在pannel1里面

如果放在solo里面,你这里应该add this 而不是panel1了。tp.add("panel1", panel1);

所以简单得做,就把//frame.add(this);  这句去掉

从而去掉你说的那个“小选项”(有这个小选项是因为你多添加了一个Jpanel进去)

再有你原来那些物件没有显示在基本信息里 是因为你的add功能没有指定JPanel,所以都添加到了solo这个Panel里面(你原来可能就是想添加在solo里,但是和其他的代码出入太多,为了简单我就按照现在这样改了)

你先看一下,是不是你想要的 还有什么问题咱们继续探讨

java泛型疑问

抱歉,前面没搞清楚,现在修正一下,关于包装类

看这句

static T T wildSubtype(Holder? extends T holder, T arg)

这句表示 wildSubtype 第一个参数必须是 HolderT的子类或本身

static T void wildSupertype(Holder? super T holder, T arg)

这句表示 wildSupertype 第一个参数必须是HolderT的超类

调用

wildSubtype(unbounded, lng);

时候,lng本身是简单数据类型

我查了一些文档,这时候T实际上被认为是Object

unbounded = new HolderLong

所以unbounded作为参数1没问题,因为满足Long extends Object

而wildSupertype则不行,因为Long super Object不满足

关于java的solo和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。