Discover database connectivity in java with mysql, include the articles, news, trends, analysis and practical advice about database connectivity in java with mysql on alibabacloud.com
Exportdb2xls(String dbname,string Xlsfilename)throwsexception{Hssfworkbook book =NewHssfworkbook (); Connection con = connsutil.getconn (); DatabaseMetaData dm = Con.getmetadata ();//When writing code, try to avoid the result set socket operation and perform other result set operations within one result set operation //If there is a transaction, a fallback or commit of one result set may spread to anotherResultSet rs = dm.gettables (DbName, DbName,NULL,Newstring[]{"TABLE"}); listN
"+rs.getstring (2)); }
}
//as you can see, query is used to process queries;//Update for INSERT, UPDATE, delete, Drop;//the other statement used for composition;//for the result set, you can also use GetString ("name") to live content;//the columns are numbered starting from 1;//
//
//then you want to close the connection;
if(rs!=NULL)//close the recordset;{Try{rs.close (); }Catch(SQLException e) {e.printstacktrace (); }
}
namesstring[] Cloumname = new String[cloumcount];for (int i = 0; i Cloumname[i] = Rs.getmetadata (). getColumnName (i + 1);//The column name pointer in the result set starts at 1, not 0System.out.println (Rs.getmetadata (). getColumnName (i + 1));}5. Remove the required fields from the result setwhile (Rs.next ()) {for (int i = 0; i Object key = Renamestr[i];Object value = rs.getstring (i + 1);if (key.equals ("Invoice type")) {if (Value.equals ("1")) {Value = "GPO";} else if (Value.equals ("3")
Tags: cep float static code block SQL multiple Learning load version todayHaven't updated the blog for a long time! Today, using day, I learned a bit about MySQL database. Introduction to the database of three ways to connect! Development tools: MyEclipse MySQL5.6 MySQL Connection driver:
The database was designed last week using the Java language and MySQL database, which involves knowledge of the Java connection database.
First we need to add a jar file that is equivalent to a driver file for the connect
Java file to demonstrate how to access the MySQL database.Note: Create database on the command line or with a SQL front-end software.Create the database First:CREATE DATABASE Scutcs;Next, create the table:CREATE TABLE STUDENT(SNO CHAR (7) Not NULL,SNAME VARCHAR (8) Not NULL,
1. first, add a reference to the MySQL database driver jar in eclipse. Right-click the project and choose Properties> JAVA build path> libraries> Add external jars, navigate to the downloaded MySQL driver jar and click OK.
2. Access code example.
package demos;import java.sql.*;public class HelloMySQL {public static
id,command,description,content from Message";
-listNewArraylist();
- if(NULL! = Command ! "". Equals (command) {
-Sb.append ("and command=?")); in paramlist.add (command); - }
to if(NULL! = Description ! "". Equals (description)) {
+ //use% in MySQL to denote any character, with a space for connection
-Sb.append ("and DESCRIPTION like '% '? ') %‘"); the Paramlist.add (description); *
After nearly one day, I finally connected to the MySQL database. Here is a brief summary:
1. Configure the MySQL database first.
2. Download the MySQL driver mysql-connector-java-5-jar
Today, I met a friend in the group and asked how to use a separate JavaProgramConnect to the MySQL database. Or any other database. I did not write this during my studies.CodeAre written in eclipse or myeclipse. Copy the jar package from the database to the Lib under the project, and then introduce it.Today, I will wri
Today depressed day, Java program to insert data to MySQL is not garbled, database installation also selected encoding for UTF8 (and my program coding format consistent). But the insertion of data into garbled, rather depressing.
Reason: The code in the MySQL configuration file is not changed to UTF8;
Solution: In th
Java connection to the mysql database and Content Query Method, javamysql
Recently, I used the framework to do several projects. I felt a little forgotten about the underlying things. I wrote a simple JDBC connection code to familiarize myself with this, I also hope it will be helpful for new users. This is also my first article. If you don't talk much about it,
Tags: psql OTF packet JD declaration not out NEC StatTransfer from Weibo: http://www.cnblogs.com/centor/p/6142775.htmlTools: EclipseMySQL5.6MySQL Connection driver: Mysql-connector-java-5.1.27.jar (link: https://pan.baidu.com/s/1MmFZ9Hve6rV0tlryM3raeA password: q74m)Load driver:1. Create the Lib folder in the project catalog and place the downloaded JDBC in the folder as shown in: 2. Right-click the projec
JDBC (Java Data Base Connectivity,java database connection) is a Java API for executing SQL statements that provides unified access to a variety of relational databases, consisting of a set of classes and interfaces written in the Java
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.