java连接到mysql [英] java connectivity to mysql
本文介绍了java连接到mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个程序,通过它我们可以将数据保存到数据库中。前端是java swing,我使用的是jdk1.5.0,后端是mysql,问题是我无法保存记录及其显示
Java.Lang.ClassNotFoundExeption:com.mysql.jdbc.Driver
和源代码是:
try {
Connection con = null;
Class.forName( com.mysql.jdbc.Driver);
con = DriverManager.getConnection( jdbc:mysql:// localhost:3306 / azim, root, < span class =code-string> apnaghar);
语句st = con.createStatement();
int i = st.executeUpdate( 插入meical(itemCode,itemName,catagory,type,suppliyer,expDate,manDate,MRP,position)值(' + t1.getText()+ ',' + t2.getText()+ ',' + lb1.getSelectedItem()+ ',' + lb2.getSelectedItem()+ ',' + t3.getText()+ ',' + t4.getText()+ ',' + t5.getText()+ ',' + t6.getText()+ ',' + t7.getText()+ ')跨度>);
JOptionPane.showMessageDialog(null, 数据已成功插入数据库。);
st.close();
con.close();
}
catch (例外e)
{
System.out.println(e);
}
}
解决方案
$ b $上的代码部分bClass.forName(com.mysql.jdbc.Driver)
找不到jdbc驱动程序。
从下载Connector / J 下载[ ^ ]
读取此内容以设置 JDBC - 环境 [ ^ ]
你没有com.mysql.jdbc.Driver,请更新它,它会工作..
i have created a program by which we can save the data into the database.front end is java swing and i am using jdk1.5.0 and back end is mysql the problem is that i not able to save the record and its showing
Java.Lang.ClassNotFoundExeption:com.mysql.jdbc.Driver
and source code is:
try{
Connection con = null;
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/azim", "root", "apnaghar");
Statement st = con.createStatement();
int i= st.executeUpdate("Insert into meical(itemCode,itemName,catagory,type,suppliyer,expDate,manDate,MRP,position) values('"+t1.getText()+"','"+t2.getText()+"','"+lb1.getSelectedItem()+"','"+lb2.getSelectedItem()+"','"+t3.getText()+"','"+t4.getText()+"','"+t5.getText()+"','"+t6.getText()+"','"+t7.getText()+"')");
JOptionPane.showMessageDialog(null,"Data is successfully inserted into the database." );
st.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
解决方案
The part of code on
Class.forName("com.mysql.jdbc.Driver")
could not find the jdbc driver.
Download it from Download Connector/J[^]
Read this to setup JDBC - Environment[^]
you don't have "com.mysql.jdbc.Driver" ,please update it ,it will work..
这篇关于java连接到mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文