java怎么从数据库读取存储的地址,希望有代码
3个回答
展开全部
public void add(Order order) throws SQLException {
DBConnection dbConnection = new DBConnection();
Connection conn = dbConnection.getConn();
String sql = "insert into hunsion.order(id_store_item,usetime, address, tel, name, amount) values(?,?,?,?,?,?);";
PreparedStatement prepareStatement = null;
try {
prepareStatement = conn.prepareStatement(sql);
prepareStatement.setInt(1, order.getId_store_item());
prepareStatement.setString(2, order.getUsetime());
prepareStatement.setString(3, order.getAddress());
prepareStatement.setString(4, order.getTel());
prepareStatement.setString(5, order.getName());
prepareStatement.setString(6, order.getAmount());
prepareStatement.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
prepareStatement.close();
conn.close();
prepareStatement = null;
conn = null;
}
}
就大概发一个数据插入的一个东西给你吧 下面我在贴一下读取的
public Connection getConn() {
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/hunsion";
String dbname = "root";
String dbpwd = "";
try {
Class.forName("org.gjt.mm.mysql.Driver");
if (conn == null) {
conn = DriverManager.getConnection(url, dbname, dbpwd);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
其实很简单的 不懂得你可以在问
DBConnection dbConnection = new DBConnection();
Connection conn = dbConnection.getConn();
String sql = "insert into hunsion.order(id_store_item,usetime, address, tel, name, amount) values(?,?,?,?,?,?);";
PreparedStatement prepareStatement = null;
try {
prepareStatement = conn.prepareStatement(sql);
prepareStatement.setInt(1, order.getId_store_item());
prepareStatement.setString(2, order.getUsetime());
prepareStatement.setString(3, order.getAddress());
prepareStatement.setString(4, order.getTel());
prepareStatement.setString(5, order.getName());
prepareStatement.setString(6, order.getAmount());
prepareStatement.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
prepareStatement.close();
conn.close();
prepareStatement = null;
conn = null;
}
}
就大概发一个数据插入的一个东西给你吧 下面我在贴一下读取的
public Connection getConn() {
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/hunsion";
String dbname = "root";
String dbpwd = "";
try {
Class.forName("org.gjt.mm.mysql.Driver");
if (conn == null) {
conn = DriverManager.getConnection(url, dbname, dbpwd);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
其实很简单的 不懂得你可以在问
展开全部
如果简单写一个jdbc连接数据库的查询
SELECT * From 表 where 条件;然后遍历得到的list,可以获取到存储的地址
SELECT * From 表 where 条件;然后遍历得到的list,可以获取到存储的地址
更多追问追答
追问
不懂,能给点示例吗?
追答
jdbc的数据库连接 网上有很多 对照自己的数据库改下驱动就能连接数据库了,
然后写sql就是查询语句也很简单,然后在模型层就可以遍历得到的list
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询